Releasing a Statement Identifier

A statement identifier can represent only one SQL statement or (in ESQL/C) one semicolon-separated list of SQL statements at a time. A new PREPARE statement can specify an existing statement identifier if you want to bind the identifier to a different SQL statement text.

The PREPARE statement supports dynamic statement-identifier names, which allow you to prepare a statement identifier as an identifier or (in ESQL/C) as a host variable of a data type that can contain a character string. The first example that follows shows a statement identifier that was specified as a host variable. The second specifies a statement identifier as a character string.
stcopy ("query2", stmtid);
EXEC SQL prepare :stmtid from 'select * from customer';

EXEC SQL prepare query2 from 'select * from customer';

The variable must be a character data type. In C, it must be declared as char.

In an SPL routine, statement identifiers that the PREPARE statement declares are automatically defined in the local scope. Do not attempt to declare a statement identifier as having local or global scope. A statement identifier defined in one SPL routine is not visible to any other SPL routine that the same session calls. SPL statement identifiers share the same namespace as SPL variables and cursor names.