SkillRary

Please login to post comment

Introduction to Pro*C

  • Amruta Bhaskar
  • Aug 3, 2020
  • 0 comment(s)
  • 3241 Views

Pro*C which is also known as Pro*C/C++ is an embedded SQL programming language that is used by Oracle Database DBMSes. As a host language, it uses either C or C++.

The embedded SQL statements are interpreted by a precompile and are replaced by C or C++ function calls to their respective SQL library during the compilation time. The output from the Pro*C precompiler is standard C or C++ code which is then compiled by one of several C or C++ compilers into an executable. 

Process of the compilation of Pro*C program:

1.   Create a C program containing SQL statements and save this file with “.PC” extension. PC stands for a program that is a Pro*C program.

2.   Now compile using PROC compiler provided by oracle. This PROC compiler generates .c file with all the SQL statements replaced by the functions which are pre-defined in the Oracle runtime library.

3.   The file that is been created by the PROC compiler will again be compiled by the C compiler, which is supported by Pro*C. In Windows, the PROC compiler supports Microsoft Visual C++ compiler.

 

4.   Now, the C compiler will create a .exe file and we run the .exe file.

   

Why Pro*C Compiler?

1.   It allows you to embed the SQL statements in the C program and also provides the required user interface.

2.   The Pro*C allows you to customize applications.

3.   It creates a user interface that incorporates the latest windowing and mouse technology.

4.   It is possible that we cannot generate the reports from other development tools, but we can achieve this by retrieving the data from the oracle database.

What are the Requirements?

1.   Install Pro*C Software.

2.   While installing the Oracle database, we have to make sure that we have selected all the Pro*C components.

3.   We can check if the installation of oracle contains the Pro*C components by checking the PRECOMP directory of Oracle.

Directory Structure

In Oracle, the directory structure is created on the hard drive for Oracle products. The main oracle directory will contain the subdirectories and files which are required for the Pro*C. Once we install the Pro*C in Oracle, then Oracle Universal installer creates a directory which is known as precomp in the ORACLE_BASE\ORACLE_HOME directory. This subdirectory, i.e., precomp contains all the executable files, library files, and some sample programs.

precomp directory structure:

Directory

Description

\admin

Contains the configuration files.

\demo\proc

Contains the sample programs for Pro*C.

\demo\sql

Contains SQL scripts for sample programs.

\doc\proc

Contains the documentation files for pro*c.

\help\proc

Contains help files for Pro*C.

\lib\msvc

Contains library files for Pro*C

\mesg

Contains message files.

\misc\proc

Contains miscellaneous files for Pro*C.

\public

Contains the header files having .h extension.

 

Restrictions.

The Windows operating systems can contain the spaces in the files and directory names, but in Oracle Pro*C precompiler, it does not precompile the files, which include space in the file name.

For example, if the file name is “the first program.pc”, then this file name will be invalid.

Embedded SQL Statements.

Embedded SQL means placing the SQL statements inside the source program.  As we place the statements inside the C program, the C program is known as the host program and the language known as the host language. The Pro*C provides the ability to embed the SQL statements inside the program.

Two types of Embedded SQL statements:

1.   Executable Statements

2.   Directives

Executable statements: The SQL statements that allow you to manipulate the data in the Oracle database. These statements call the Oracle runtime library. It also allows your program to connect to the Oracle database, to define the query, to manipulate the data, and process the transactions. These statements are written where C executable statements can be placed.

Directives: The SQL statements that neither call the Oracle runtime libraries nor operate on the Oracle data. It is used to declare the Oracle objects, SQL objects. These statements can be written where the C variables can be declared.

Pro*C Syntax

Here in the C program, all the SQL statements must start with EXEC SQL and should end with the semicolon “;”. We can write the SQL statement anywhere in the program but with one restriction that declarative statements should not come after the executable statements.

Example:

Retrieve the student marks from the database based on their id.

Then its program would be written as:

 {   

 int marks;  

 EXEC SQL select marks INTO : marks from student where student_id=6;  

 printf("The marks of the student is : %d", marks);  

 

 }  


Please login to post comment

( 0 ) comment(s)