How Does Oracle directly run the OS command (on)
How Does Oracle directly run the OS command (on)
The ORACLE tutorial is: how to directly run the OS command (on) in Oracle ).
In Oracle 8i, operating system commands are often run during the storage process. Generally, Oracle Enterprise Manager can be used to set jobs. However, due to the lack of flexibility in the setup of OEM jobs, the set job parameters are fixed. In practical applications, operating system commands must be run in SQL statements at any time. Oracle 8i does not directly run the OS command. We can use the DBMS_PIPE package to implement this requirement.
DBMS_PIPE creates an MPS queue to allow at least two processes to communicate with each other. The Oracle pipeline and the operating system pipeline have the same concept, but the implementation mechanism is different.
The following describes the implementation steps:
1. Create a package named DAEMON. The SQL statement is as follows:
/* Create a daemon package */
Create or replace package body daemon
/* Execute_system is a function used to run OS commands */
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 );
/* Send the character indicating the command to the daemon Pipeline */
Status: = DBMS_PIPE.SEND_MESSAGE ('daemon', timeout );
IF status <> 0 THEN
RAISE_APPLICATION_ERROR (-20010,
'Execute _ system: Error while sending. Status = '| status );
End if;