Book Image

Advanced Oracle PL/SQL Developer's Guide (Second Edition) - Second Edition

By : Saurabh K. Gupta
Book Image

Advanced Oracle PL/SQL Developer's Guide (Second Edition) - Second Edition

By: Saurabh K. Gupta

Overview of this book

Oracle Database is one of the most popular databases and allows users to make efficient use of their resources and to enhance service levels while reducing the IT costs incurred. Oracle Database is sometimes compared with Microsoft SQL Server, however, Oracle Database clearly supersedes SQL server in terms of high availability and addressing planned and unplanned downtime. Oracle PL/SQL provides a rich platform for application developers to code and build scalable database applications and introduces multiple new features and enhancements to improve development experience. Advanced Oracle PL/SQL Developer's Guide, Second Edition is a handy technical reference for seasoned professionals in the database development space. This book starts with a refresher of fundamental concepts of PL/SQL, such as anonymous block, subprograms, and exceptions, and prepares you for the upcoming advanced concepts. The next chapter introduces you to the new features of Oracle Database 12c, not limited to PL/SQL. In this chapter, you will understand some of the most talked about features such as Multitenant and Database In-Memory. Moving forward, each chapter introduces advanced concepts with the help of demonstrations, and provides you with the latest update from Oracle Database 12c context. This helps you to visualize the pre- and post-applications of a feature over the database releases. By the end of this book, you will have become an expert in PL/SQL programming and will be able to implement advanced concepts of PL/SQL for efficient management of Oracle Database.
Table of Contents (19 chapters)
Advanced Oracle PL/SQL Developer's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 extproc process for loading the required library are $ORACLE_HOME/bin and $ORACLE_HOME/lib. For testing purposes, we will continue with the defaults....