Executing external C programs from PL/SQL
Let's us walk through an illustration on how to execute an external procedure, written in the C language, in the Oracle Database.
Step 1: Creating and compiling the C program.
The following C program (
GetMax.c) finds the maximum of the two number values:#include <stdio.h> /* Define the function returning the max between two numbers */ int GetMax(int num1, int num2) { /* local variable declaration */ int result; if (num1 > num2) result = num1; else result = num2; return result; }Compile the program by using a C compiler.
sh-4.3# gcc -c GetMax.c
Step 2: Generating the DLL and creating the library object in the Oracle Database.
We will now generate the DLL for the C program:
sh-4.3# gcc -shared GetMax.c -o GetMax.dll
The library location
The default paths searched by the
extprocprocess for loading the required library are$ORACLE_HOME/binand$ORACLE_HOME/lib. For testing purposes, we will continue with the defaults....