#docslug#/obci/obci/V1.2.0/rcroho
In an application, you can call library functions provided by OceanBase Call Interface (OBCI) to manipulate OceanBase Database. To be compatible with Oracle, all OBCI functions are prefixed with OCI and have the same names as Oracle OCI functions. This enables developers to manipulate OceanBase Database in existing Oracle applications by calling the same OCI functions, without the need to modify a single line of code.
The following describes the basic development procedure in an OBCI program:
Initialize the OBCI environment and threads.
Allocate necessary handles and data structures.
Establish a connection to the database and create a user session.
Exchange data with the OceanBase server by using SQL statements, and then perform data processing.
End the user session and disconnect from the database.
Release the handles allocated.
The following figure illustrates the basic development procedure in an OBCI application. For more information about the code, see Development examples.

One of the most common tasks of an OBCI program is to accept and process SQL statements. The foregoing has described the basic development procedure in the OBCI program. The following describes how to process SQL statements in the OBCI program.
The following figure shows the steps of executing an SQL statement in the OBCI program and the functions called in each step.

Call the OCIStmtPrepare() or OCIStmtPrepare2() function to prepare an SQL statement.
Bind the SQL statement with variables that need to be passed to the SQL statement. For a DML statement that has input variables, you can call one or more functions, such as OCIBindByPos() and OCIBindByName(), to bind the address of each input variable to the placeholder in the DML statement.
Call the OCIStmrExecute() function to execute the SQL statement. For a DDL statement, its execution ends at this step.
Describe the output data of the SQL statement. If necessary, you can call the OCIParamGet() and OCIAttGet() functions to get the following attributes of the record read: the number of fields, the data types of the fields, and the maximum length defined for the field data.
Define the output variables. If necessary, you can call the OCIDefineByPos() function to define output variables for the data output items of the SQL statement. Note that you cannot define output variables by calling the OCIDefineByPos() function in an anonymous PL/SQL block. This is because you have completed this step during data binding.
Fetch data. You can call the OCIStmtFetch() function where necessary to fetch the result set of a query.
The following example describes how OBCI calls functions on a Linux system. The example shows how to create, delete, insert, update, and query data in the person table. The oci.h header file of OBCI is used during the compilation, and the libobci.so or libobci.a library file is used in the linking phase.
Notice
If you are building a dynamic link to libobci.so, you also need to manually install the OBClient RPM package. If you are building a static link to libobci.a, the OBClient RPM package is not required.
Sample statement:
Static link:
gcc example.c -I/u01/obclient/include /u01/obclient/lib/libobci.a -L/usr/local/lib64 -lstdc++ -lpthread -ldl -lm -g -o example
Dynamic link:
gcc example.c -I/u01/obclient/include -L/u01/obclient/lib/ -L/usr/local/lib64 -lobci -lobclnt -g -o example
Execution output:
export LD_LIBRARY_PATH=/u01/obclient/lib:$LD_LIBRARY_PATH
$./example
PERSONID NAME EMAIL
finish fetch data
finish insert tables
PERSONID NAME EMAIL
1 obtest t@ob.com
finish fetch data
PERSONID NAME EMAIL
1 test test@mail
finish fetch data
PERSONID NAME EMAIL
finish fetch data