Wednesday, May 14, 2014

Static cursors and Dynamic cursors in DB2

Coming to the cursor types, before DB2 v7, we could only move/scroll through  the cursor in forward position.So when the cursor is opened, the pointer would be positioned before the first row in the result set. Once the FETCH as been issued, the pointer would move one row forward.
NO SCROLL is the default and indicates that the cursors are not scrollable.This is the normal cursor which commonly gets used in application program.

DB2 V7 introduced STATIC SCROLLABLE CURSOR  which can be scrolled backwards or
forwards, and to an absolute position or to a relative position.When the CURSOR is opened, the qualifying rows would be placed in a  declared temporary table automatically created by DB2.Scrolling is performed on the temporary table in both the forward direction and backward direction. DB2 deletes the result table when the cursor is closed.

With the introduction of DB2 v8, the concept of DYNAMIC SCROLLABLE CURSOR has been introduced. Dynamic cursors DO NOT need any temporary table.This is one of the main difference between static and dynamic cursors. They SCROLL on the main table itself, and therefore are sensitive to all the  committed inserts, updates, and deletes. Thus the overhead in building the temporary table(as in static cursor)  and maintaining the synchronization between the base table and result table is not there in case of dynamic cursor.

Declare cursor statements:
DECLARE CURSOR statements for static and dynamic cursors

NO SCROLL is the default and indicates that the cursors are not scrollable. If you specify
SCROLL, the cursors become scrollable.
For  Dynamic CURSORS we can have the below attributes:
1. SENSITIVE DYNAMIC SCROLLABLE
2. ASENSITIVE SCROLLABLE

 ******* NOTE: There is no DYNAMIC option for INSENSITIVE CURSOR. *********

1 comment:

  1. I really appreciate the information shared above. It’s of great help. If someone wants to learn Online (Virtual) instructor lead live training in IBM Mainframe TECHNOLOGY, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor-led training on TECHNOLOGY. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ pieces of training in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Pratik Shekhar
    MaxMunus
    E-mail: pratik@maxmunus.com
    Ph:(0) +91 9066268701
    http://www.maxmunus.com/

    ReplyDelete