Closes an open cursor.
exec sql [at connection_name] close cursor_name;
The name of the cursor to be closed; that is, the name that you assigned when declaring the cursor.
long SQLCODE;
exec sql begin declare section;
CS_CHAR mlname[40];
CS_CHAR mfname[20];
CS_CHAR phone[12];
exec sql end declare section;
exec sql declare author_list cursor for
select au_lname, au_fname, phone
from authors;
exec sql open author_list;
while (SQLCODE == 0) {
exec sql fetch author_list into
:mlname, :mfname, :mphone;
if(SQLCODE != 100)
printf(“%s, %s, %s\n”, mlname, mfname,
mphone);
}
exec sql close author_list;
The close statement closes an open cursor. Unfetched rows are canceled.
Reopening a closed cursor executes the associated query again, positioning the cursor pointer before the first row of the result set.
A cursor must be closed before it is reopened.
Attempting to close a cursor that is not open causes a runtime error.
The commit transaction, rollback transaction, commit work, and rollback work statements close a cursor automatically unless you set a precompiler option to disable the feature.
Closing and then reopening a cursor lets your program see any changes in the tables from which the cursor retrieves rows.
declare cursor, fetch, open, prepare