SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
2-1
2 Embedded SQL Statements
You can access an SQL/MX database by embedding SQL statements in your host
language program.
This section describes:
Syntax for Coding SQL Statements on page 2-1
Guidelines for Coding SQL Statements on page 2-1
Placement of SQL Statements on page 2-2
Embedded SQL Declarations and Statements on page 2-6
Using CONTROL Statements on page 2-12
Static and Dynamic CONTROL Statements on page 2-13
Syntax for Coding SQL Statements
To code an embedded SQL statement in your 3GL source file, use this general syntax:
sql-statement
is any SQL statement shown in Embedded SQL Declarations and Statements on
page 2-6.
sql-terminator
is the terminator for the SQL statement.
For C/C++, sql-terminator is a semicolon (;).
For COBOL, sql-terminator is END-EXEC.
Guidelines for Coding SQL Statements
Follow the same formatting and line continuation conventions for embedded SQL
statements that you use for 3GL statements.
Example
EXEC SQL WHENEVER SQLERROR PERFORM 9000-SQL-ERROR END-EXEC.
EXEC SQL
SELECT custname
INTO :HV-CUSTNAME
FROM customer
WHERE custnum = :HV-THIS-CUSTOMER
END-EXEC.
An SQL statement can extend over several lines.
SQL statements cannot be nested.
EXEC SQL sql-statement sql-terminator
COBOL