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 ...

Get Advanced Oracle PL/SQL Developer's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.