DECLARE CURSOR |
Top Previous Next |
Syntax <declare_cursor> ::= DECLARE [VARIABLE] cursor_name CURSOR FOR (<select>);
A cursor is a special variable that can be used in your code later on by referring to its name cursor_name. The SELECT-statement is a regular SQL select statement which can include JOINs, a WHERE clause and so on. It can select one or multiple columns for the result set.
Example In the example below, you can see the cursor "mycursor" being declared with a SELECT-statement selecting a single column from a table and applying an ordering.
execute udsblock() returns(out_int integer) as declare mycursor cursor for (select v from DUMMY_ROWS_10 order by v desc); begin /* open the cursor result set */ open mycursor;
/* fetch data from the first row */ fetch mycursor into out_int;
/* close the cursor */ close mycursor; end
|