Page 1 of 1

Fetching a empty table

PostPosted: Fri Sep 20, 2013 10:41 pm
by nikesh_rai
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.

Re: Fetching a empty table

PostPosted: Fri Sep 20, 2013 11:03 pm
by Akatsukami
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'.

Re: Fetching a empty table

PostPosted: Fri Sep 20, 2013 11:23 pm
by nikesh_rai
Thanks Akatsukami.. :)