When to use cursor?

IBM's flagship relational database management system

When to use cursor?

Postby sunilkumar1244 » Thu Aug 13, 2009 6:43 pm


Can anyone please tell me in detail when to use cursor.
While using cursor when to use single fetch and when to use multifetch.

Posts: 4
Joined: Tue Jul 21, 2009 5:49 pm
Has thanked: 0 time
Been thanked: 0 time

Re: When to use cursor?

Postby GuyC » Thu Aug 13, 2009 7:16 pm

it's more a db2 question then a cobol question.

Cursor vs single select : If you're select returns more than one row (and you need those rows), you'll have to use a cursor.
If you only need the first one (but you're not allowed to "order by") you could use a single select with "fetch first 1 row only".

Cursors :
Multi-row fetching is more performant then single row fetching,but it complicates your program a bit.
Once you have a decent skeleton or example program its easy.

If you expect to do more then 1000 fetches, i would advise to certainly switch to multi-row.
But even for smaller cursors : once you're used to it : always use it.

if you google "multi-row fetch" you'll find all kind of interesting articles.

one being : http://it.toolbox.com/blogs/db2zos/why- ... cool-12229
I can explain it to you, but i can not understand it for you.
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times

Return to DB2


  • Related topics
    Last post