fetch

SQL/PL

Fetch the next row from a cursor

Syntax

fetch_stmt:
          FETCH [NEXT] [FROM] cursor_name INTO var_name[, var_name]...

Description

The FETCH statement is used to fetch the next row from the SELECT statement associated with cursor cursor_name.

Each result column value is stored in its corresponding var_name. The number of variables specified must match the number of columns in the result row and each must be declared with the same (or compatible) data type as its associated result column.

The first FETCH after the last row of the result set has been fetched will close the cursor and raise the NOT FOUND exception.

Example

declare gr_than_avg cursor for select * from acctmgr; 		...   open gr_than_avg;   get_next1: loop       fetch gr_than_avg into l_id, l_name, l_date, l_comm;       if not found then           leave get_next1;       end if;       if l_date >= lo_date and l_date <= hi_date then            set comm_sum = comm_sum + l_comm;           set comm_count = comm_count + 1;       end if;   end loop get_next1;   close gr_than_avg;

See Also

DECLARE CURSOR

CLOSE

OPEN