How Does Oracle directly run the OS command (below) page 1/2

Source: Internet
Author: User

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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.