Page 1 of 1

When to use cursor?

PostPosted: Thu Aug 13, 2009 6:43 pm
by sunilkumar1244
Hello,

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

Thanks.

Re: When to use cursor?

PostPosted: Thu Aug 13, 2009 7:16 pm
by GuyC
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