Associated and Detached Statements
When a cursor is automatically freed, its associated prepared statement (or associated statement) is also freed.
The term associated statement has a special meaning in the context of the Autofree feature. A cursor is associated with a prepared statement if it is the first cursor that you declare with the prepared statement, or if it is the first cursor that you declare with the statement after the statement is detached.
The term detached statement has a special meaning in the context of the Autofree feature. A prepared statement is detached if you do not declare a cursor with the statement, or if the cursor with which the statement is associated was freed.
/*Cursor associated with a prepared statement */
EXEC SQL prepare sel_stmt 'select * from customer';
EXEC SQL declare sel_curs2 cursor for sel_stmt;
FREE sel_curs2;
FREE sel_stmt;
Because memory for the sel_stmt statement is freed automatically, you cannot declare a new cursor on it unless you prepare the statement again.