Cursor (databases) - "WITH HOLD"

"WITH HOLD"

Cursors are usually closed automatically at the end of a transaction, i.e. when a COMMIT or ROLLBACK (or an implicit termination of the transaction) occurs. That behavior can be changed if the cursor is declared using the WITH HOLD clause. (The default is WITHOUT HOLD.) A holdable cursor is kept open over COMMIT and closed upon ROLLBACK. (Some DBMS deviate from this standard behavior and also keep holdable cursors open over ROLLBACK.)

DECLARE cursor_name CURSOR WITH HOLD FOR SELECT ... FROM ...

When a COMMIT occurs, a holdable cursor is positioned before the next row. Thus, a positioned UPDATE or positioned DELETE statement will only succeed after a FETCH operation occurred first in the transaction.

Note that JDBC defines cursors as holdable per default. This is done because JDBC also activates auto-commit per default. Due to the usual overhead associated with auto-commit and holdable cursors, both features should be explicitly deactivated at the connection level.

Read more about this topic:  Cursor (databases)

Famous quotes containing the word hold:

    Some hours seem not to be occasion for any deed, but for resolves to draw breath in. We do not directly go about the execution of the purpose that thrills us, but shut our doors behind us and ramble with prepared mind, as if the half were already done. Our resolution is taking root or hold on the earth then, as seeds first send a shoot downward which is fed by their own albumen, ere they send one upward to the light.
    Henry David Thoreau (1817–1862)

    Indeed, men never know how to love. nothing satisfies them. All they know is to dream, to imagine new duties, to look for new countries and new homes. While we women, we know that we must hasten to love, to share the same bed, hold hands, and fear absence. When we women love, we dream of nothing.
    Albert Camus (1913–1960)