DECLARE STATEMENT — declare SQL statement identifier
EXEC SQL [ AT
DECLARE STATEMENT declares an SQL statement identifier. SQL statement identifier can be associated with the connection. When the identifier is used by dynamic SQL statements, the statements are executed using the associated connection. The namespace of the declaration is the precompile unit, and multiple declarations to the same SQL statement identifier are not allowed. Note that if the precompiler runs in Informix compatibility mode and some SQL statement is declared, "database" can not be used as a cursor name.
A database connection name established by the
AT clause can be omitted, but such statement has no meaning.
The name of an SQL statement identifier, either as an SQL identifier or a host variable.
This association is valid only if the declaration is physically placed on top of a dynamic statement.
EXEC SQL CONNECT TO postgres AS con1; EXEC SQL AT con1 DECLARE sql_stmt STATEMENT; EXEC SQL DECLARE cursor_name CURSOR FOR sql_stmt; EXEC SQL PREPARE sql_stmt FROM :dyn_string; EXEC SQL OPEN cursor_name; EXEC SQL FETCH cursor_name INTO :column1; EXEC SQL CLOSE cursor_name;
DECLARE STATEMENT is a extension of the SQL standard, but can be used in famous DBMSs.