Create a working directory (c:\tempextproc for example), and place the following code in a file called getempno.pc
/* 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);
}
Open a Visual Studio command prompt (Start > Programs > Microsoft Visual Studio 2008 > Visual Studio Tools > Visual Studio 2008 Command Prompt , and move the command prompt into that irectory.
Set ORACLE_HOME and MSVCDIR environment variables by issuing the following at a command prompt (adjust paths for your environment):
set oracle_home=D:\oracle\product\11.2.0\dbhome_1
set MSVCDIR="D:\Program Files\Microsoft Visual Studio 9.0\VC"
Precompile the .pc file using the following command (all on one line), which will result in the creation of getempno.c :
In this case, we'll copy the dll to %ORACLE_HOME%\bin for simplicity
copy getempno.dll %ORACLE_HOME%\BIN\getempno.dll
At this point, getempno.dll will have a dependency on MSVCR90.DLL which likely does not exist in the PATH, so it will need to be copied to %ORACLE_HOME%\bin, or the following error will result at runtime:
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:
Member for
16 years 3 monthshere is the p6 fixCreate a
here is the p6 fix
#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 MSVCDIR="D:\Program Files\Microsoft Visual Studio 9.0\VC"
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:
==================================
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:
mt.exe -manifest Microsoft.VC90.CRT.manifest -outputresource:msvcr90.dll;2
for further information, refer to MSDN Documentation
and create the library, create the procedure wrapper, and test it by running the code below
/
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;
https://msdn.microsoft.com/en-us/library/ms235560(VS.80).aspx