Fetching a empty table



IBM's flagship relational database management system

Fetching a empty table

Postby nikesh_rai » Fri Sep 20, 2013 10:41 pm

Hi Guys,

When we will try to fetch a empty table using cursor, we will get SQLERROR Code +100. Can you please tell me at which step we will get this error, while opening the cursor or at the time of fetching it. Since OPEN CURSOR is the only executable step and extract the data from table and sort it, if any order by clause is specified, where as fetch cursor will only return rows one by one to the application program, so I think the error code should be generated at OPEN Cursor step.

Can you guys please help me.
Thanks
Nikesh Rai
nikesh_rai
 
Posts: 205
Joined: Tue Oct 18, 2011 1:27 am
Has thanked: 17 times
Been thanked: 0 time

Re: Fetching a empty table

Postby Akatsukami » Fri Sep 20, 2013 11:03 pm

nikesh_rai wrote:Hi Guys,

When we will try to fetch a empty table using cursor, we will get SQLERROR Code +100. Can you please tell me at which step we will get this error, while opening the cursor or at the time of fetching it. Since OPEN CURSOR is the only executable step and extract the data from table and sort it, if any order by clause is specified, where as fetch cursor will only return rows one by one to the application program, so I think the error code should be generated at OPEN Cursor step.

You are incorrect. As the fine manual states:
If the table is empty, the position of the cursor is effectively “after the last row.” The DB2® system does not indicate an empty table when the OPEN statement is executed. A subsequent fetch for the cursor might return the SQLSTATE warning of '02000'.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day

These users thanked the author Akatsukami for the post:
nikesh_rai (Fri Sep 20, 2013 11:23 pm)
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Fetching a empty table

Postby nikesh_rai » Fri Sep 20, 2013 11:23 pm

Thanks Akatsukami.. :)
Thanks
Nikesh Rai
nikesh_rai
 
Posts: 205
Joined: Tue Oct 18, 2011 1:27 am
Has thanked: 17 times
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post