The declare statement is similar to the standard declare statement for cursors. In dynamic SQL, however, you declare the cursor for a prepared statement_name instead of for a select statement, and any input host variables are referenced in the open statement instead of in the declare statement.
A dynamic declare statement is an executable statement rather than a declaration. As such, it must be positioned in the code where executable statements are legal, and the application should check status codes (SQLCODE, SQLCA, or SQLSTATE) after executing the declaration.
The dynamic SQL syntax for the declare statement is:
exec sql [at connection_name] declare cursor_name
cursor for statement_name;
where:
at connection_name specifies the Adaptive Server connection the cursor will use.
cursor_name identifies the cursor, used with the open, fetch, and close statements.
statement_name is the name specified in the prepare statement, and represents the select statement to be executed.