How Does Oracle directly run the OS command (below)
How Does Oracle directly run the OS command (below)
The ORACLE tutorial is: how to directly run the OS command (below) in Oracle ). Exec SQL WHENEVER SQLERROR CONTINUE;
Sqlglm (msg_buffer, & buffer_size, & msg_length );
Printf ("Daemon error while connecting: \ n ");
Printf ("%. * s \ n", msg_length, msg_buffer );
Printf ("Daemon quitting. \ n ");
Exit (1 );
}
Void
SQL _error ()
{
Char msg_buffer [512];
Int msg_length;
Int buffer_size = 512;
Exec SQL WHENEVER SQLERROR CONTINUE;
Sqlglm (msg_buffer, & buffer_size, & msg_length );
Printf ("Daemon error while executing: \ n ");
Printf ("%. * s \ n", msg_length, msg_buffer );
Printf ("Daemon continuing. \ n ");
}
Main ()
{
Exec SQL WHENEVER SQLERROR DO connect_error ();
Exec SQL CONNECT: uid;
Printf ("Daemon connected. \ n ");
Exec SQL whenever sqlerror do SQL _error ();
Printf ("Daemon waiting... \ n ");
While (1 ){
EXEC SQL EXECUTE
BEGIN
/* Receive characters from deamon */
: Status: = DBMS_PIPE.RECEIVE_MESSAGE ('daemon ');
IF: status = 0 THEN
/* Extract characters */
DBMS_PIPE.UNPACK_MESSAGE (: command );
End if;
END;
END-EXEC;
IF (status = 0)
{
Command. arr [command. len] = '\ 0 ';
/* If it is stop, the process will exit */
IF (! Strcmp (char *) command. arr, "STOP "))
{
Printf ("Daemon exiting. \ n ");
Break;
}
Else if (! Strcmp (char *) command. arr, "SYSTEM "))
{
EXEC SQL EXECUTE
BEGIN
DBMS_PIPE.UNPACK_MESSAGE (: return_name );
DBMS_PIPE.UNPACK_MESSAGE (: value );
END;
END-EXEC;
Value. arr [value. len] = '\ 0 ';
Printf ("Will execute system command '% s' \ n", value. arr );
/* Run the OS command */
Status = system (value. arr );
EXEC SQL EXECUTE
BEGIN
DBMS_PIPE.PACK_MESSAGE ('done ');
DBMS_PIPE.PACK_MESSAGE (: status );
: Status: = DBMS_PIPE.SEND_MESSAGE (: return_name );
END;
END-EXEC;