During the development of C language, it is necessary to operate the database. Generally, Oracle Pro*C/C++ precompiler is used to use Oracle database.

This article describes the Oracle Pro*C/C++ precompiler, its role in developing applications that manipulate Oracle data, and what it enables your applications to do. Specific such as use.

This chapter describes embedded SQL syntax, coding conventions, and C-specific capabilities and limitations.


The statement

A DECLARE SELECT contains the host variable declaration and of the form:

EXEC SQL SELECT ENAME, SAL INTO :emp_name, :salary FROM EMP WHERE DEPTNO = :dept_number;Copy the code

The statement begins with a statement:

EXEC SQL BEGIN DECLARE SECTION;
Copy the code

And concluded with a statement:

EXEC SQL END DECLARE SECTION;
Copy the code

Only the following is allowed between the two statements:

  • Host variable and indicator variable declarations
  • Non-host C/C++ variables
  • EXEC SQL DECLARE statement
  • EXEC SQL INCLUDE statements
  • EXEC SQL VAR statement
  • EXEC SQL TYPE statement
  • The EXEC ORACLE statement
  • C/C + + comments

Host variable name

Host variable names can consist of uppercase or lowercase letters, numbers, and underscores, but must start with a letter and can be any length, but only the first 31 characters are meaningful to Pro*C/C++. A C compiler or linker may require a shorter maximum length, so check out the C compiler user’s guide.

For portability, Anglo-Irish limits the length of host variable names to 18 characters or less (the length specified by the SQL standard).

constant

A large or rising suffix specifies a long integer constant, a u or U suffix specifies an unsigned integer constant, a 0X or 0X prefix specifies a hexadecimal integer constant, and a ˚F or ˚F suffix specifies a float floating point constant. These forms are not allowed to be used in SQL statements.

An inter-bank continue

You can continue the SQL statement from one line to the next. You must use a backslash () to continue the string literal from one line to the next, as shown in the following example:

EXEC SQL INSERT INTO dept (deptno, dname) VALUES (50.'PURCHAS\ ING');
Copy the code

In this case, the precompiler treats the backslash as a continuous character.

The operator

The logical operator and the “equal” relational operator are different in C and SQL, as shown in the following table. These C operations are not allowed in SQL statements:

SQL operator. C operator.
not !
and &&
or ||
= = =

The following C operators are also not allowed in SQL statements:

type C operator.
address &
An operation &, | ^. ~
The compound assignment +=, -=, *=
Conditions of the assignment ? :
diminishing
increasing ++
indirect *
Modulus of %
transfer > >, < <

MAXLITERAL default values

The MAXLITERAL precompiler option allows you to specify the maximum length of string literals generated by the precompiler.

MAXLITERAL The default value is 1024. Specify a smaller value if needed. For example, if your C compiler cannot handle string literals longer than 512 characters, specify MAXLITERAL=512. Check the C compiler user guide.