Specify a statement block.

 

Syntax

 

<compound statement> ::=

 

 

 

BEGIN [ [ NOT ] ATOMIC ]

[ <local declaration list> ]

[ <SQL statement list> ]

END

 

<local declaration list> ::= { <SQL variable declaration> ; }...

 

<SQL statement list> ::= { <SQL procedure statement> ; }...

 

 

Usage

 

The Compound statement is used to specify a sequence of SQL procedure statements inside a BEGIN..END block.

 

 

Notes

 

NOT ATOMIC is implicit if neither ATOMIC nor NOT ATOMIC is specified.



 

If ATOMIC is specified, then an internal transaction is started before the statement block is executed. The transaction is committed only if all the statements in the block executed successfully, otherwise the transaction is rolled back.



 

All SQL variable declarations shall be specified before other SQL statements.



 

 

Examples

 

1)

The following example shows a Compound statement with parameter declarations:



 


DROP FUNCTION IF EXISTS dummyFunc;


CREATE FUNCTION dummyFunc ()


RETURNS DOUBLE PRECISION


BEGIN




DECLARE d1, d2 DOUBLE PRECISION;


SET d1 = 25;


SET d2 = 4;


RETURN d1 * d2;




END;


SELECT dummyFunc FROM #dummy;



 

 


 

Conformance

 

SQL:2003 standard

-

-

SQL/PSM Feature P002-01 "Compound statement"

Beginning and ending statement labels are not supported