Programmer's Guide to the Oracle Call Interface
Release 8.0






Prev Next

Introduction and New Features

This chapter introduces you to the Oracle Call Interface, Release 8.0. It gives you background information that you need to develop applications using the OCI. It also introduces special terms that are used in discussing the OCI.

This chapter also discusses the changes in the OCI since release 7.3.

The following topics are covered:

The Oracle Call Interface

Structured Query Language (SQL) is a nonprocedural language. A program in a nonprocedural language specifies the set of data to be operated on, but does not specify precisely what operations will be performed, or how the operations are to be carried out. The nonprocedural nature of SQL makes it an easy language to learn and to use to perform database transactions. It is also the standard language used to access and manipulate data in modern relational and object-relational database systems.

However, most programming languages, such as C and C++ are procedural. The execution of most statements depends on previous or subsequent statements and on control structures, such as loops or conditional branches, which are not available in SQL. The procedural nature of these languages makes them more complex than SQL, but it also makes them very flexible and powerful.

The OCI allows you to develop applications that combine the nonprocedural data access power of SQL with the procedural capabilities of C. The OCI supports all SQL data definition, data manipulation, query, and transaction control facilities that are available through the Oracle8 Server.

You can also take advantage of PL/SQL, Oracle's procedural extension to SQL. Thus, the applications you develop can be more powerful and flexible than applications written in SQL alone. The OCI also provides facilities for accessing and manipulating objects in an Oracle8 Server.

The OCI is an application programming interface (API) that allows you to manipulate data and schemas in an Oracle database. As Figure 1-1 shows, you compile and link an OCI program in the same way that you compile and link a nondatabase application. There is no need for a separate preprocessing or precompilation step.

Figure 1-1 The OCI Development Process

Note: On some platforms, it may be necessary to include other libraries, in addition to the OCI library, to properly link your OCI programs. Check your Oracle system-specific documentation for further information about extra libraries that may be required.

SQL Statements

One of the main tasks of an OCI application is to process SQL statements. Different types of SQL statements require different processing steps in your program. It is important to take this into account when coding your OCI application.

Oracle8 recognizes eight kinds of SQL statements:

Note: Queries are often classified as DML statements, but OCI applications process queries differently, so they are considered separately here.

Data Definition Language

Data Definition Language (DDL) statements manage schema objects in the database. DDL statements create new tables, drop old tables, and establish other schema objects. They also control access to schema objects. For example:

CREATE TABLE employees
    (name               VARCHAR2(20),
          ssn                  VARCHAR2(12),
          empno              NUMBER(6),
          mgr                  NUMBER(6),
          salary            NUMBER(6))

REVOKE UPDATE ON employees FROM scott

DDL statements also allow you to work with objects in the Oracle8 Server, as in the following series of statements which creates an object table:

        name                VARCHAR2(30),
        ssn                  VARCHAR2(12),
        address          VARCHAR2(50))

CREATE TABLE person_tab OF person_t

Control Statements

OCI applications treat transaction control, session control, and system control statements like DML statements. See the Oracle8 Server SQL Reference for information about these types of statements.

Data Manipulation Language

Data manipulation language (DML) statements can change data in the database tables. For example, DML statements are used to

DML statements can require an application to supply data to the database using input (bind) variables. See the section "Binding" on page 4-5 for more information about input bind variables.

DML statements also allow you to work with objects in the Oracle8 Server, as in the following example, which inserts an instance of type person_t into the object table person_tab:

INSERT INTO person_tab
        VALUES (person_t('Steve May','123-45-6789','146 Winfield Street'))


Queries are statements that retrieve data from a database. A query can return zero, one, or many rows of data. All queries begin with the SQL keyword SELECT, as in the following example:

SELECT dname FROM dept
        WHERE deptno = 42

Queries access data in tables, and they are often classified with DML statements. However, OCI applications process queries differently, so they are considered separately in this guide.

Queries can require the program to supply data to the database using input (bind) variables, as in the following example:

SELECT name 
FROM employees
WHERE empno = :empnumber

In the above SQL statement, :empnumber is a placeholder for a value that will be supplied by the application.

When processing a query, an OCI application also needs to define output variables to receive the returned results. In the above statement, you would need to define an output variable to receive any name values returned from the query.

See Also: See the section "Binding" on page 5-2 for more information about input bind variables.
See the section "Defining" on page 5-14 for information about defining output variables.
See Chapter 4, "SQL Statement Processing", for detailed information about how SQL statements are processed in an OCI program.


PL/SQL is Oracle's procedural extension to the SQL language. PL/SQL processes tasks that are more complicated than simple queries and SQL Data manipulation language statements. PL/SQL allows a number of constructs to be grouped into a single block and executed as a unit. Among these are:

You can use PL/SQL blocks in your OCI program to

The following PL/SQL example issues a SQL statement to retrieve values from a table of employees, given a particular employee number. This example also demonstrates the use of placeholders in PL/SQL statements.

        SELECT ename, sal, comm INTO :emp_name, :salary, :commission
        FROM emp
        WHERE ename = :emp_number;

Keep in mind that the placeholders in this statement are not PL/SQL variables. They represent input values passed to Oracle when the statement is processed. These placeholders need to be bound to C language variables in your program.

See Also: See the PL/SQL User's Guide and Reference for information about coding PL/SQL blocks.
See the section "Binding Placeholders in PL/SQL" on page 5-5 for information about working with placeholders in PL/SQL.

Embedded SQL

The OCI processes SQL statements as text strings, which an application passes to Oracle on execution. The Oracle precompilers (Pro*C/C++, Pro*COBOL, Pro*FORTRAN) allow programmers to embed SQL statements directly into their application code. A separate precompilation step is then necessary to generate an executable application.

It is possible to mix OCI calls and embedded SQL in a precompiler program. Refer to the Programmer's Guide to the Pro*C/C++ Precompiler for more information.

Special OCI/SQL Terms

This guide uses special terms to refer to the different parts of a SQL statement. For example, a SQL statement such as

SELECT customer, address
		FROM customers
		WHERE bus_type = 'SOFTWARE'
		AND sales_volume = :sales

contains the following parts:

When you develop your OCI application, you call routines that specify to the Oracle8 Server the address (location) of input and output variables in your program. In this guide, specifying the address of a placeholder variable for data input is called a bind operation. Specifying the address of a variable to receive select-list items is called a define operation.

For PL/SQL, both input and output specifications are called bind operations.

These terms and operations are described in detail in Chapter 4.

Object Support in the OCI

With Release 8.0, the Oracle Server has facilities for working with object types and objects. An object type is a user-defined data structure representing an abstraction of a real-world entity. For example, the database might contain a definition of a person object. That object might have attributes-first_name, last_name, and age-which represent a person's identifying characteristics.

The object type definition serves as the basis for creating objects, which represent instances of the object type. Using the object type as a structural definition, a person object could be created with the attributes `John', `Bonivento', and `30'.

Object types may also contain methods-programmatic functions that represent the behavior of that object type.

See Also: For a more detailed explanation of object types and objects, see Oracle8 Server Concepts.

The Oracle8 OCI includes functions that extend the capabilities of the OCI to handle objects in an Oracle8 Server. Specifically, the following capabilities have been added to the OCI:

Additional OCI calls are provided to support manipulation of objects after they have been accessed by way of SQL statements.

Note: For a more detailed description of enhancements and new features, please refer to Appendix F, "Oracle8 OCI New Features".

Parts of the OCI

The OCI encompasses four main sets of functionality:

These terms are used throughout this guide.

Release 8.0 New Features

The Oracle8 OCI provides a wide range of new features and functions. All calls available in Release 7.3 are still supported, but they are not able to take full advantage of new Oracle8 features.

Note: For a more detailed description of enhancements and new features, please refer to Appendix F, "Oracle8 OCI New Features".

Release 8.0 has the following new features and performance advantages:

Each of these features is discussed in greater detail in later chapters of this guide.

Release 8.0 of the OCI contains an entirely new set of API calls that replace those used in earlier releases. Additionally, new calls are included to provide functionality not available in earlier releases.

See Also: See the section "Obsolescent OCI Routines" on page A-2 for information about new calls that supersede existing routines.
See Chapters 13, 14, 15, and 16 for complete listings of all OCI calls.

Obsolescent and Obsolete OCI Calls

Refer to Appendix A for lists of OCI calls that are now considered to be obsolescent or obsolete.

Compiling and Linking

Oracle Corporation supports most popular third-party compilers. The details of linking an OCI program vary from system to system. See your Oracle system-specific documentation and the installation guide for more information about compiling and linking an OCI application for your specific platform.


Copyright © 1997 Oracle Corporation.

All Rights Reserved.