Oracle数据库中如何直接运行OS命令
status := DBMS_PIPE.RECEIVE_MESSAGE(pipe_name, timeout);
IF status <> 0 THEN
RAISE_APPLICATION_ERROR(-20011,
'Execute_system: Error while receiving.
Status = ' status);
END IF;
/*获取返回结果*/
DBMS_PIPE.UNPACK_MESSAGE(result);
IF result <> 'done' THEN
RAISE_APPLICATION_ERROR(-20012,
'Execute_system: Done not received.');
END IF;
DBMS_PIPE.UNPACK_MESSAGE(command_code);
DBMS_OUTPUT.PUT_LINE('System command executed. result = '
command_code);
RETURN command_code;
END execute_system;
/*stop是让daemon停止*/
PROCEDURE stop(timeout NUMBER DEFAULT 10) IS
status NUMBER;
BEGIN
DBMS_PIPE.PACK_MESSAGE('STOP');
status := DBMS_PIPE.SEND_MESSAGE('daemon', timeout);
IF status <> 0 THEN
RAISE_APPLICATION_ERROR(-20030,
'stop: error while sending. status = ' status);
END IF;
END stop;
END daemon;
通过Sql*Plus运行以上语句,将为当前用户创建daemon程序包。
2、创建在OS上运行的守护进程,监听由上面的daemon程序包发来的要求执行os命令的语句。以下Pro*C的代码,必须由pro*c先进行预编译。