Oracle Pro * C learning notes

xiaoxiao2021-03-06  18

Currently in rebuilding a service program under Linux, it is necessary to use Oracle's Pro * C. Here is a learning transcription:

First, Pro * C Introduction

In addition to providing database access tools such as SQL * Plus, SQL * Forms, Oracle can access the Oracle database in a third-generation SQL statement or ORACLE function in the third-generation advanced language. Currently, Oracle support has C, Fortran, Pascal, etc., called Pro * C, using C. The embedded SQL statement includes a DML, DDL statement, which enables dynamic establishment, modification, deleting tables in the database, or querying, inserting, deleting in the table in the table in the table, implementing the submission and rollback of database operations . The advantage of the SQL statement in the third-generation advanced language is the following three points:

1. The combination of procedural language and non-processed languages ​​can meet the applications of various complex requirements, and can also be referenced to the window and mouse technology.

2, enable development applications with ability to manage resources, SQL statements and indicators

3. Improve the execution speed of the application.

All Pro * C procedures are precompiled by Oracle's pre-compilation systems before compiling, and the precompiled system allows for dynamic SQL technology to implement the conversion of internal and external data types, which can be embedded in PL / SQL blocks. Type Equivalence Control Oracle Interprets Input Data and Format Output Data, you can check the syntax and semantics of embedded SQL statements, you can use the array SQL variables to use SQLCA and ORACA error diagnostics.

Second, Pro * C program structure

General Pro * C mainly includes two parts: two parts: the program body.

External Description Segment: The external variables and functions to be cited in the program are mainly indicated, including relevant claims, communication area descriptions, and C language.

Program main: The main part of the same general C program, multiple functions can be used or only the main function. The function can also include a partial description segment, a local communication area declaration, and a C-local variable declaration.

The segment syntax is as follows:

EXEC SQL Begin Declare Section;

(SQL variable declaration)

Exec SQL End Declare Section;

Description Segment is used to declare the type declaration statement that contains: SQL variables; EXEC SQL include statement; Exec SQL VAR statement; Exec SQL VAR statement; but does not allow SQL variables that are declared as structural types.

The communication area description statement is: EXEC SQL INCLUDE SQLCA;

Where SQLCA is structured, the specific content can be viewed in the header file of the Oracle Precuplication System SQLCA.H (the path under Windows: $ orahome / precomp / public /)

Struct Sqlca {Char SQLCAID [8]; / * Communication area ID, (declare multiple times is not used by ID?) int SQLABC; / * Communication area length int SQLCode; / * Contact with SQLCode Indicates SQL Error Code struct {/ * Structure is equivalent to SQLERRM users to store SQL error messages. Unsigned short sqlerrml; / * Error information text length char SQlerRMC [70]; / * Error information text} SQlerrm; char sqlerrp [8]; int sqlerrd [6]; char SQLWARN [8]; / * SQL statement warning char sqlext [ 8];}; 3, data type

(1), SQL variable: SQL variable is introduced in order to implement information between C and SQL statements, SQL variables can be used in two statements, but C variables can only be used in C.

(2), internal data type: refers to what formats in Oracle puts data in the database table column, (Oracle's unique data type) See the table below

(3), external data type: Refers to how to store data in SQL variables, including Oracle's full internal data types and C's data types. See the table below

(4), the data type of the SQL variable can be specified in the description segment. See the table below

Data Type Description CHAR Single Character Char [N] Characters Arunte INT Multiple SHORT Short Integer LONG Long Integer Float Single Joint Floating Point Double Double Double Precision Floating Point VARCHAR [N] Various Strings

转载请注明原文地址:https://www.9cbs.com/read-46685.html

New Post(0)