Firebird Documentation IndexFirebird 2.0 Language Ref. UpdatePSQL statements → DECLARE
Firebird Home Firebird Home Prev: CLOSE cursorFirebird Documentation IndexUp: PSQL statementsNext: EXCEPTION

DECLARE

DECLARE ... CURSOR
DECLARE [VARIABLE] with initialization

Available in: PSQL

DECLARE ... CURSOR

Added in: 2.0

Description: Declares a named cursor and binds it to its own SELECT statement. The cursor can later be opened, used to walk the result set, and closed again. Positioned updates and deletes are also supported. PSQL cursors are available in triggers, stored procedures and EXECUTE BLOCK statements.

Syntax: 

DECLARE [VARIABLE] cursorname CURSOR FOR (select-statement);

Example: 

execute block
returns (relation char(31), sysflag int)
as
declare cur cursor for 
  (select rdb$relation_name, rdb$system_flag from rdb$relations);
begin
  open cur;
  while (1=1) do
  begin
    fetch cur into relation, sysflag;
    if (row_count = 0) then leave;
    suspend;
  end
  close cur;
end

See also: OPEN cursor, FETCH cursor, CLOSE cursor

DECLARE [VARIABLE] with initialization

Changed in: 1.5

Description: In Firebird 1.5 and above, a PSQL local variable can be initialized upon declaration. The VARIABLE keyword has become optional.

Syntax: 

DECLARE [VARIABLE] varname datatype [{= | DEFAULT} value];

Example: 

create procedure proccie (a int)
returns (b int)
as
declare p int;
declare q int = 8;
declare r int default 9;
declare variable s int;
declare variable t int = 10;
declare variable u int default 11;
begin
  <intelligent code here>
end
Prev: CLOSE cursorFirebird Documentation IndexUp: PSQL statementsNext: EXCEPTION
Firebird Documentation IndexFirebird 2.0 Language Ref. UpdatePSQL statements → DECLARE