在Oracle
DBMS_PIPE通過創建管道
下面介紹實現具體步驟:
/*創建daemon程序包*/
CREATE OR REPLACE PACKAGE BODY daemon AS
/*execute_system是實現運行os命令的函數*/
FUNCTION execute_system(command VARCHAR
timeout NUMBER DEFAULT
RETURN NUMBER IS
status NUMBER;
result VARCHAR
command_code NUMBER;
pipe_name VARCHAR
BEGIN
pipe_name := DBMS_PIPE
DBMS_PIPE
DBMS_PIPE
DBMS_PIPE
/*向daemon管道發送表示命令的字符*/
status := DBMS_PIPE
IF status <>
RAISE_APPLICATION_ERROR(
END IF;
status := DBMS_PIPE
IF status <>
RAISE_APPLICATION_ERROR(
Status =
END IF;
/*獲取返回結果*/
DBMS_PIPE
IF result <>
RAISE_APPLICATION_ERROR(
END IF;
DBMS_PIPE
DBMS_OUTPUT
command_code);
RETURN command_code;
END execute_system;
/*stop是讓daemon停止*/
PROCEDURE stop(timeout NUMBER DEFAULT
status NUMBER;
BEGIN
DBMS_PIPE
status := DBMS_PIPE
IF status <>
RAISE_APPLICATION_ERROR(
END IF;
END stop;
END daemon;
通過Sql*Plus運行以上語句
#include
#include
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
char *uid =
int status;
VARCHAR command[
VARCHAR value[
VARCHAR return_name[
EXEC SQL END DECLARE SECTION;
void
connect_error()
{
char msg_buffer[
int msg_length;
int buffer_size =
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlglm(msg_buffer
printf(
printf(
printf(
exit(
void
sql_error()
{
char msg_buffer[
int msg_length;
int buffer_size =
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlglm(msg_buffer
printf(
printf(
printf(
}
main()
{
EXEC SQL WHENEVER SQLERROR DO connect_error();
EXEC SQL CONNECT :uid;
printf(
EXEC SQL WHENEVER SQLERROR DO sql_error();
printf(
while (
EXEC SQL EXECUTE
BEGIN
/*接收deamon發來的字符*/
:status := DBMS_PIPE
IF :status =
/*取出字符*/
DBMS_PIPE
END IF;
END;
END
IF (status ==
{
command
/*如果是stop
IF (!strcmp((char *) command
{
printf(
break;
}
ELSE IF (!strcmp((char *) command
{
EXEC SQL EXECUTE
BEGIN
DBMS_PIPE
DBMS_PIPE
END;
END
value
printf(
/*運行os命令*/
status = system(value
EXEC SQL EXECUTE
BEGIN
DBMS_PIPE
DBMS_PIPE
:status := DBMS_PIPE
END;
END
IF (status)
{
printf
(
printf(
}
}
ELSE
{
printf
(
command
}
}
ELSE
{
printf(
printf(
}
}
EXEC SQL COMMIT WORK RELEASE;
exit(
}
From:http://tw.wingwit.com/Article/program/Oracle/201311/17426.html