21.10.2013 Views

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Notes:<br />

PSQL statements<br />

as<br />

begin<br />

for select town, pop from towns into :town, :pop as cursor tcur do<br />

begin<br />

if (town = towntodelete)<br />

then delete from towns where current of tcur;<br />

else suspend;<br />

end<br />

end<br />

• A “FOR UPDATE” clause is allowed in the SELECT statement., but not required for a positioned update or<br />

delete to succeed.<br />

• Make sure that cursor names defined here do not clash with any names created earlier on in DECLARE CUR-<br />

SOR statements.<br />

• AS CURSOR is not supported in FOR EXECUTE STATEMENT loops, even if the statement to execute is a<br />

suitable SELECT query.<br />

Available in: PSQL<br />

Added in: 1.5<br />

Changed in: 2.0<br />

LEAVE<br />

Description: LEAVE immediately terminates the innermost WHILE or FOR loop. With the optional label argument<br />

introduced in <strong>Firebird</strong> 2.0, LEAVE can break out of surrounding loops as well. Execution continues with<br />

the first statement after the outermost terminated loop.<br />

Syntax:<br />

Example:<br />

[label:]<br />

{FOR | WHILE} ... DO<br />

...<br />

(possibly nested loops, with or without labels)<br />

...<br />

LEAVE [label];<br />

If an error occurs during the insert in the example below, the event is logged and the loop terminated.<br />

The program continues at the line of code reading “c = 0;”<br />

while (b < 10) do<br />

begin<br />

insert into Numbers(B) values (:b);<br />

b = b + 1;<br />

when any do<br />

begin<br />

execute procedure log_error (current_timestamp, 'Error in B loop');<br />

106

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!