Example compiling an External Procedure using Pro*C Callback on Windows platform (文档 ID 1271017.1)
Modified Date Label修改日期Modified Date06-JAN-2011Document Type Label类型Document TypeSAMPLE CODE状态REVIEWED(EXTERNAL)优先级3转到底部
In this Document
Purpose
Software Requirements/Prerequisites
Configuring the Sample Code
Running the Sample Code
Caution
Sample Code
Sample Code Output
/* getempno.pc */
#include <sqlca.h>
#include <oci.h>
int __declspec(dllexport) get_empno(OCIExtProcContext *epctx)
{
int empno=0;
EXEC SQL REGISTER CONNECT USING :epctx;
EXEC SQL SELECT empno INTO :empno FROM emp where ename='KING';
return(empno);
}
set oracle_home=D:\oracle\product\11.2.0\dbhome_1
set MSVCDIR="D:\Program Files\Microsoft Visual Studio 9.0\VC"
proc iname=getempno.pc oname=getempno.c parse=full include=%ORACLE_HOME%\oci\include include=%ORACLE_HOME%\precomp\public include=%MSVCDir%\include
cl -I%ORACLE_HOME%\oci\include -I%MSVCDir%\include -I%ORACLE_HOME%\precomp\public -Zi getempno.c /LD /link %ORACLE_HOME%\oci\lib\msvc\oci.lib %ORACLE_HOME%\precomp\lib\orasql11.lib msvcrt.lib /nod:libcmt /DLL
copy getempno.dll %ORACLE_HOME%\BIN\getempno.dll
ERROR at line 1:
ORA-06520: PL/SQL: Error loading external library
ORA-06522: Unable to load DLLERROR at line 1:
ORA-06520: PL/SQL: Error loading external library
ORA-06522: Unable to load DLL
First, however, it will need to have the manifest incorporated into it or the following error will result at runtime:
Microsoft Visual Studio C++ Runtime Library
==================================
Runtime Error!
Program: d:\oracle\product\11.2.0\dbhome_1\bin\extproc.exe
R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
To create the manifest, move the VS2010 command prompt into the MSVCRT redistributable folder and issue the following:
cd %MSVCDIR%redist\x86\Microsoft.VC90.CRT
mt.exe -manifest Microsoft.VC90.CRT.manifest -outputresource:msvcr90.dll;2
for further information, refer to MSDN Documentation
copy msvcr90.dll %ORACLE_HOME%\bin\msvcr90.dll
sqlplus scott/tiger
and create the library, create the procedure wrapper, and test it by running the code below
drop library empnolib;
/
create library empnolib as 'D:\oracle\product\11.2.0\dbhome_1\bin\getempno.dll';
/
create or replace function get_empno
return binary_integer as
external library empnolib
name "get_empno"
language C
with context
parameters(context);
/
select getempno from dual;
This sample code is provided for educational purposes only and not supported by Oracle Support Services. It has been tested internally, however, and works as documented. We do not guarantee that it will work for you, so be sure to test it in your environment before relying on it.
Proofread this sample code before using it! Due to the differences in the way text editors, e-mail packages and operating systems handle text formatting (spaces, tabs and carriage returns), this sample code may not be in an executable state when you first receive it. Check over the sample code to ensure that errors of this type are corrected.
SQL> select get_empno from dual;
GET_EMPNO
----------
7839
SQL>