5. Working with a Database : How You Can Access a Database with Standard SQL Statements : How You Can Use Cursors to Access the Database : How You Can Manage Transactions with Cursors
 
Share this page                  
How You Can Manage Transactions with Cursors
Each cursor must be opened and closed within a single transaction. Moreover, the state of the transaction affects the state of the cursor. For example, a cursor is automatically closed in either of the following cases:
Its transaction is closed by either a commit or rollback.
Its transaction is aborted by an error.
Some errors (for example, deadlock, logfull, and disk full) do not abort an entire transaction but do close any open cursors. If an error occurs while a cursor is open, you should roll back the transaction and begin it again.
If you are running with autocommit on (each database statement is a separate transaction), a cursor is considered one transaction from the time it is opened until it is closed. Therefore, when autocommit is on and a cursor is open, you can issue only cursor statements to access the database. If you issue any other database access statements, the open cursor is closed automatically.
For an explanation of using autocommit, see How Running with Autocommit On Works (see How Running with Autocommit On Works).
You can use the inquire_sql statement with the transaction parameter to determine the transaction state. For more information about the inquire_sql statement, see Handling Database Errors (see Handling Database Errors) or the online help.