Including Embedded SQL Statements

You can include Embedded SQL statements in the portions of your C code where C functions or routines can be placed. To distinguish Embedded SQL statements from the C source code, each Embedded SQL statement must begin with the introductory keyword EXEC SQL and end with a semicolon (;). An Embedded SQL statement that does not end with a semicolon (;) usually results in sqlprep compiler error –19104 "Incorrect SQL statement syntax."

You can use a backslash ( \ ) to continue SQL strings across more than one line of source code. A single quote must precede the first character of the SQL string on the first line of source code, and a single quote must appear after the last character of the SQL string on the last line of source code. For example:


EXEC SQL INSERT INTO TEXT132 VALUES ('TEST 192 IS THE TEST FOR THE R\
ULE OF THE CONTINUATION OF LINES FROM ONE LINE TO THE NEXT LINE.');

You can also insert C language code after the EXEC SQL keyword on the same line. For example:


EXEC SQL COMMIT TRAN; printf("\n");

Note

To include C language code after an EXEC SQL keyword on the same line, you must use the /NOLINES precompiler option.

You can also include Embedded SQL variable declaration sections in C language code where it is valid to declare variables. Use the BEGIN DECLARE SECTION and END DECLARE SECTION statements.