SQL control statements for SQL routines (SQL PL)

The SQL procedural language (SQL PL) is a set of 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:
Read syntax diagramSkip visual syntax diagramassignment-statementCALL statementCASE statementcompound-statementFOR statementGET DIAGNOSTICS statementGOTO statementIF statementITERATE statementLEAVE statementLOOP statementREPEAT statementRESIGNAL statementRETURN statementSIGNAL statementWHILE 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 (SQL - native) statement. An SQL procedure can be changed. A new SQL routine body can be specified in an ALTER PROCEDURE (SQL - native) 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: