oracle中os命令,Oracle数据库中如何直接运行OS命令

/*创建daemon程序包*/

CREATE OR REPLACE PACKAGE BODY daemon AS

/*execute_system是实现运行os命令的函数*/

FUNCTION execute_system(command VARCHAR2,

timeout NUMBER DEFAULT 10)

RETURN NUMBER IS

status NUMBER;

result VARCHAR2(20);

command_code NUMBER;

pipe_name VARCHAR2(30);

BEGIN

pipe_name := DBMS_PIPE.UNIQUE_SESSION_NAME;

DBMS_PIPE.PACK_MESSAGE("SYSTEM");

DBMS_PIPE.PACK_MESSAGE(pipe_name);

DBMS_PIPE.PACK_MESSAGE(command);

/*向daemon管道发送表示命令的字符*/

status := DBMS_PIPE.SEND_MESSAGE("daemon", timeout);

IF status <> 0 THEN

RAISE_APPLICATION_ERROR(-20010,

"Execute_system: Error while sending. Status = " || status);

END IF; [page]

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值