Index   Search   Add FAQ   Ask Question  
 

Please note: This page is not maintained anymore. Please visit the new and improved page at http://www.orafaq.com/wiki/Precompilers

Oracle Precompiler FAQ

$Date: 13-Sep-2001 $
$Revision: 1.53 $
$Author: Frank Naudé $

Topics

  • What is a precompiler and what is it used for?
  • What languages are supported?
  • What is the difference between OCI and the Precompilers?
  • Should I use Pro*C V1 or V2?
  • How does one compile a precompiler program?
  • How does one compile a PRO*C program?
  • How can I tell Pro*C what directory my header files are in?
  • What is an indicator variable and why should I use it?
  • How does one execute PL/SQL code from Pro*C?
  • Where can one get more info about the Oracle Precompilers?

  • Back to Oracle FAQ Index

    What is a precompiler and what is it used for?

    A precompiler is a tool that allows programmers to embed SQL statements in high-level source programs like C, C++, COBOL, etc. The precompiler accepts the source program as input, translates the embedded SQL statements into standard Oracle runtime library calls, and generates a modified source program that one can compile, link, and execute in the usual way. Examples are the Pro*C Precompiler for C, Pro*Cobol for Cobol, SQLJ for Java etc.

  • Back to top of file

  • What languages are supported?

    The following 3GL languages are supported by the Oracle precompilers: Please note that Oracle8 does not support Pascal, PL/I and Ada. For Java related issues, visit the JDBC/JSQL FAQ.

  • Back to top of file

  • What is the difference between OCI and the Precompilers?

    The Oracle OCI (Oracle Call Interface), is an alternate low-level interface to the Oracle database.

    The SQL precompilers for the various host languages (Pro*C, Pro*Ada, Pro*Fortran, Pro*COBOL, etc.) reads EXEC SQL commands and generate data structures and calls to its runtime library: SQLLIB (libsql.a in UNIX). SQLLIB, in turn, calls the User Program Interface (UPI) to communicate with the database. It does not generate calls to the Oracle Call Interface (OCI) but you can mix OCI and Precompiler calls.

    For more info about the Oracle Call Interfaces, see the OCI FAQ.

  • Back to top of file

  • Should I use Pro*C V1 or V2?

    Try to make the switch to version 2.0 as soon as possible. Starting with Oracle7 release 7.3, it will be the only version available. The support matrix: Because Pro*C 2.x behaves differently from Pro*C 1.x, and to ease migration, both versions of Pro*C were shipped with 7.1 and 7.2. I recommend using 2.x or higher for any new development. You can use the PARSE=PARTIAL or PARSE=NONE options to get behavior similar to version 1.x.

  • Back to top of file

  • How does one compile a precompiler program?

    The following syntax is used to precompile a Pro*C program:
         proc iname=myprog.pc host=C
    
    Oracle includes some sample precompiler programs with it's installation. These are normally located under the $ORACLE_HOME/precomp/demo/proc (or related) directories.

    After you've precompiled your program, invoke the standard host language compiler and linker. Also remember, if you modify your source code, change the original precompiled source program. In C, for example, you would modify the *.PC file and not the *.C file. The *.C file gets overwritten every time you precompile your program.

    Look at the following table for other host languages:

  • Back to top of file

  • How does one compile a PRO*C program?

    You can study the sample makefile provided by Oracle and construct your own, but it would probably be better to just use "make" to precompile and then compile your program in one step. Look at this Unix examples:

    Oracle7:

       make -f $ORACLE_HOME/precomp/demo/proc/proc.mk build EXE=myprog OBJS=myprog.o
    

    Oracle8:

       make -f $ORACLE_HOME/precomp/demo/proc/demo_proc.mk build EXE=myprog OBJS=myprog.o
    
    NOTE: OBJS and EXE has to be entered in caps!!!

  • Back to top of file

  • How can I tell Pro*C what directory my header files are in?

    Is there some way to tell the Pro*C preprocessor to search other directories for include (*.h) files, similar to the C compiler switch "-I"? I am hoping to avoid having to change all of my #include statements...

    As documented in the Pro*C manual (in the chapter called "Running the Precompiler") there is an INCLUDE flag that can be used for this. Look at this example:

       proc iname=inputfile.pc include=directory1 include=directory2...
    
  • Back to top of file

  • What is an indicator variable and why should I use it?

    Indicator variables are used to explicitly handle NULL values. When you SELECT or FETCH a NULL value into a host variable/array an "ORA-01405: fetched column values is NULL" run-time error will result.

    This behaviour was introduced with Oracle7 when you recompiled your programs with the DBMS=V7 (the default) precompiler option.

    One workaround for this is to use the NVL() function to prevent the selection of NULL values.

    Example:

       EXEC SQL SELECT ENAME, SAL, COMM
                INTO   :emp_name, :emp_sal, :emp_comm:comm_indicator
                FROM   emp;
       if (comm_indicator == -1)
           pay = emp_sal;
       else
           pay = emp_sal + emp_comm;
    
  • Back to top of file

  • How does one execute PL/SQL code from Pro*C?

    Look at this example:
            EXEC SQL EXECUTE
                 begin
                   dbms_application_info.set_client_info('My C Program with embedded PL/SQL');
                 end;
            END-EXEC;
    

  • Back to top of file

  • Where can one get more info about the Oracle Precompilers?

  • Back to top of file
  • HOME | ASK QUESTION | ADD FAQ | SEARCH | E-MAIL US