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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

DML statements<br />

ROWS can also be used with the SELECT and UPDATE statements.<br />

Available in: DSQL<br />

Added in: 2.0<br />

Changed in: <strong>2.1</strong><br />

EXECUTE BLOCK<br />

Description: Executes a block of PSQL code as if it were a stored procedure, optionally with input and output<br />

parameters and variable declarations. This allows the user to perform “on-the-fly” PSQL within a DSQL context.<br />

Syntax:<br />

EXECUTE BLOCK [()]<br />

[RETURNS ()]<br />

AS<br />

[]<br />

BEGIN<br />

[]<br />

END<br />

::= = ? [, ]<br />

::= [, ]<br />

::= paramname [NOT NULL] [COLLATE collation]<br />

::= sql_datatype | [TYPE OF] domain<br />

::= See PSQL::DECLARE for the exact syntax<br />

Examples:<br />

This example injects the numbers 0 through 127 and their corresponding ASCII characters into the<br />

table ASCIITABLE:<br />

execute block<br />

as<br />

declare i int = 0;<br />

begin<br />

while (i < 128) do<br />

begin<br />

insert into AsciiTable values (:i, ascii_char(:i));<br />

i = i + 1;<br />

end<br />

end<br />

The next example calculates the geometric mean of two numbers and returns it to the user:<br />

execute block (x double precision = ?, y double precision = ?)<br />

returns (gmean double precision)<br />

as<br />

begin<br />

gmean = sqrt(x*y);<br />

suspend;<br />

end<br />

59

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

Saved successfully!

Ooh no, something went wrong!