FOR SELECT ... DO

Top  Previous  Next

The FOR SELECT-statement is a special version of the SELECT INTO-statement.

 

The INTO clause is mandatory and is followed by a DO-clause followed by a single statement or block statement.

 

Syntax

[WITH <cte> [, <ct> ...]]

FOR SELECT

  [<limit clause>]

  [{ALL | DISTINCT}] <select_list>

FROM <table_reference> [, <table_reference> ... ]

[WHERE <search_condition>]

... other SQL SELECT-statement clauses ...

[ORDER BY <sort_spec> [, <sort_spec> ... ]]

INTO <variable_list>
DO <compound_statement>

 

This statement will loop the result set and execute the DO-section once for each row, the loop will end when the result set has been exhausted. If no rows are returned, the DO-clause will never be executed.

 

Example

execute udsblock

as

declare ovc2 varchar(128);

declare o1 integer;

begin

  for select rdb$relation_id, rdb$relation_name 

  from rdb$relations

  into :o1, :ovc2;

  do begin

   /* display a dialog with the table name */

       GUI.ShowMessage('Table found: ' || :ovc2);

     end;

end