Calling external C dynamic library functions in Oracle

Source: Internet
Author: User

Calling external C dynamic library functions in Oracle
In order to shorten the development time, the project must call the C program that has been developed externally in Oracle.
I found some posts on the Internet and summarized the article based on the actual situation. Hope to help you.
Reference: http://www.cnblogs.com/mathitlin99/archive/2013/09/05/3303717.html

First, compile the external dynamic library libDialPlan. so

 
  1. gcc -fPIC -c LibDialPlan.cpp
  2. gcc -shared -o libDialPlan.so LibDialPlan.o -lstdc++

Modify the Oracle TNS file and listener file.
It is unclear whether the direct copy is available. If you have any questions, pay attention to the equal sign and the spaces on both sides of the brackets.
Tnsnames. ora

 
  1. ORADB =
  2. (DESCRIPTION =
  3. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.69.166)(PORT = 1521))
  4. (CONNECT_DATA =
  5. (SERVER = DEDICATED)
  6. (SERVICE_NAME = oradb)
  7. )
  8. )

  9. EXTPROC_CONNECTION_DATA=
  10. (DESCRIPTION=
  11. (ADDRESS_LIST=
  12. (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
  13. )
  14. (CONNECT_DATA=
  15. (SID = PLSExtProc)
  16. (PRESENTATION = RO)
  17. )
  18. )
Listener. ora
 
  1. LISTENER =
  2. (DESCRIPTION_LIST =
  3. (DESCRIPTION =
  4. (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
  5. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.69.166)(PORT = 1521))
  6. )
  7. )

  8. ADR_BASE_LISTENER = /home/oracle/db/app


  9. SID_LIST_LISTENER =
  10. (SID_LIST =
  11. (SID_DESC =
  12. (GLOBAL_DBNAME = oradb)
  13. (SID_NAME = oradb)
  14. )
  15. (SID_DESC=
  16. (SID_NAME = PLSExtProc)
  17. (ORACLE_HOME = /opt/local/oracle/app/product/11.2.0/dbhome_2)
  18. (ENVS = EXTPROC_DLLS=ANY)
  19. (PROGRAM = extproc)
  20. )
  21. )

Restart the listener after modification: lsnrctl stop; lsnrctl start
Check the listening status. The following listening items should appear: PLSExtProc
 
  1. [root@localhost admin]# lsnrctl status

  2. LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 04-AUG-2016 19:33:50

  3. Copyright (c) 1991, 2009, Oracle. All rights reserved.

  4. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
  5. STATUS of the LISTENER
  6. ------------------------
  7. Alias LISTENER
  8. Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
  9. Start Date 04-AUG-2016 16:23:54
  10. Uptime 0 days 3 hr. 9 min. 55 sec
  11. Trace Level off
  12. Security ON: Local OS Authentication
  13. SNMP OFF
  14. Listener Parameter File /opt/local/oracle/app/product/11.2.0/dbhome_2/network/admin/listener.ora
  15. Listener Log File /opt/local/oracle/app/product/11.2.0/dbhome_2/network/log/listener.log
  16. Listening Endpoints Summary...
  17. (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  18. (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.69.166)(PORT=1521)))
  19. Services Summary...
  20. Service "PLSExtProc" has 1 instance(s).
  21. Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
  22. Service "oradb" has 1 instance(s).
  23. Instance "oradb", status UNKNOWN, has 1 handler(s) for this service...
  24. The command completed successfully
  25. [root@localhost admin]#
Create Oraclelibrary object
 
  1. create or replace library hytpdtbilldb.Fun_Ext_Proc
  2. as '/opt/local/Oracle_install/Oracle_Call_External_C/libDialPlan.so';
Create a function
1) According to the online article, there is also a parameter.
However, this parameter cannot be compiled after I add it. The removed function does not affect the use of the function.
2) The numbers and strings correspond to the binary_integer and varchar2 types. Originally, input parameters of C require array type, but Oracle does not have a real array and can only be replaced by strings.
3) during my testing, I occasionally need to restart to call the function normally. Pay attention to the usage process.
 
  1. create or replace function hytpdtbilldb.Air2Gsi
  2. (x binary_integer,y varchar2)
  3. return varchar2
  4. as
  5. language C
  6. library hytpdtbilldb.Fun_Ext_Proc
  7. name "Air2Gsi";
  8. /


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.