3. Statements : OpenROAD SQL Statements : Fetch Statement : Examples—Fetch Statement
 
Share this page                  
Examples—Fetch Statement
Check the State attribute of the CursorObject to determine whether there are remaining rows:
fetch emp_cursor into :emp_name = name, :emp_age =
          age;
if emp_cursor.State = CS_CURRENT then
          /* A new row has been fetched. */
...
elseif emp_cursor.State = CS_NO_MORE_ROWS then
          /* All rows have been fetched. */
...
else
          /* There is an error. */
endif;
Check the RowCount attribute of the CursorObject to check the number of rows that have been retrieved:
/* Fetches no more than 5 rows from CursorObject */
if emp_cursor.RowCount <= 5 then
     fetch emp_cursor into :emp_name = name, :emp_age =
          age;
else
     close emp_cursor;
endif;