SQL control statements for SQL routines
SQL control statements for SQL routines can be used in SQL
functions and native SQL procedures. SQL control statements provide the
capability to control the logic flow, declare and set variables, and handle warnings and exceptions.
Some SQL control statements include other nested SQL statements.
SQL-control-statement:
>>-+-assignment-statement------+------------------------------->< +-CALL statement------------+ +-CASE statement------------+ +-compound-statement--------+ +-FOR statement-------------+ +-GET DIAGNOSTICS statement-+ +-GOTO statement------------+ +-IF statement--------------+ +-ITERATE statement---------+ +-LEAVE statement-----------+ +-LOOP statement------------+ +-REPEAT statement----------+ +-RESIGNAL statement--------+ +-RETURN statement----------+ +-SIGNAL statement----------+ '-WHILE statement-----------'
Control statements are supported in SQL functions and SQL procedures.
- SQL functions are created by specifying LANGUAGE SQL and an SQL routine body in a CREATE FUNCTION (compiled SQL) statement. An SQL function can be changed. A new SQL routine body can be specified in an ALTER FUNCTION (compiled SQL) statement.
- SQL procedures are created by specifying LANGUAGE SQL and an SQL routine body in a CREATE PROCEDURE (native SQL) statement. An SQL procedure can be changed. A new SQL routine body can be specified in an ALTER PROCEDURE (native SQL) statement.
The SQL routine body is the executable part of the function or procedure and is transformed by DB2® into a program.
The remainder of the topics about SQL control statements for SQL routines contain information about references to SQL parameters and variables, SQL condition names, SQL cursor names, labels, and reference information for the use of the statements that constitute the SQL routine body.
The two common elements that are used in describing specific SQL control statements are:
- SQL control statements as described above
- SQL-procedure-statement