Using EXTPROC to call shared libraries or dynamic linked libraries during database storage can indirectly call operating system commands.

Source: Internet
Author: User

1 database Program
describes how to access the shared library or dynamic link library of the operating system using the library function of the Oracle database. (DLL)
1.1 Environment Settings
l check whether the EXTPROC program is correctly installed. Run the following command in the operating system:
$ ORACLE_HOME/bin // EXTPROC
If the following words are displayed, the installation is correct
Oracle Corporation --- Wednesday Jan 24 2007 14:58:30. 598
heterogeneous agent release 10.1.0.4.0-production
l check whether the environment variables are set correctly:
$ echo $ LD_LIBRARY_PATH
the result should be:
$ ORACLE_HOME/lib:/usr/lib: $ ORACLE_HOME/CTX/lib
if not, you need to set
LD_LIBRARY_PATH = $ ORACLE_HOME/lib:/usr/lib: $ ORACLE_HOME/CTX/lib
export LD_LIBRARY_PATH

1.2 database settings
The default settings of the database usually exist. If not, add relevant content.
1.2.1 listener. ora File Settings
Make sure that the related settings of EXTPROC already exist in the file. If not, add it.
Sid_list_listener =
(Sid_list =
(Sid_desc =
(Global_dbname = cmstest)
(ORACLE_HOME =/u01/APP/Oracle/product/10.1.0/db_1)
(Sid_name = cmstest)
)
(Sid_desc =
(Sid_name = plsextproc)
(ORACLE_HOME =/u01/APP/Oracle/product/10.1.0/db_1)
(Program = EXTPROC)
)
)

Listener =
(Description =
(Address = (Protocol = TCP) (host = 10.30.2.21) (Port = 1521 ))
(Address = (Protocol = IPC) (Key = extproctest ))
)
After modifying the file, you need to restart the listener:
$ ORACLE_HOME/bin/LSNRCTL stop
$ ORACLE_HOME/bin/LSNRCTL start
1.2.2 tnsnames. ora File Settings
If extproc_connection_data is not available, you need to add it. Note that the name cannot be changed. If the sqlnet. ora file requires additional domain information, you can add it as required, such as extproc_connection_data.zte.com.cn.
In addition, the key and Sid must be consistent with those in listener. ora.
Extproc_connection_data =
(Description =
(Address_list =
(Address = (Protocol = IPC) (Key = extproctest ))
)
(CONNECT_DATA =
(SID = plsextproc)
))
1.3 example
L compile a program that calls the operating system commands and use the editor to compile a C program: EXTPROC. c
---- Program Code Start ---------
Int sysrun (char * command)
{
Return System (command );
}
----- Program code ends --------
L use the make command to compile the C program into a. So Program
Make-F $ ORACLE_HOME/rdbms/demo/demo_rdbms.mk extproc_no_context shared_libname = EXTPROC. So objs = EXTPROC. o
L copy the file EXTPROC. So to the directory $ ORACLE_HOME/lib
Cp extproc. So $ ORACLE_HOME/lib /.
L create a library in the database
SQL> Create or replace library shell_lib as '$ ORACLE_HOME/lib/EXTPROC. so ';
L create a database Stored Procedure and establish contact with the program in EXTPROC
Create or replace procedure sysrun (syscomm in varcha2)
Language C
Name "sysrun"
Library shell_lib
Parameters (syscomm string );
L in this way, you can run the command of the operating system, such:
Begin
-- Name all files under the directory to j01.txt
Sysrun ('/bin/LS-L>/tmp/j01.txt ');
-- Run SQL * Loader
Sysrun ('$ ORACLE_HOME/bin/sqlldr userid = <connection string> control = <Control File Name> ');
End;

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.