The set of statements constituting the main tasks of the stored procedure is called the stored procedure body, which can consist of a single statement or a compound statement, or block.
A single statement stored procedure body can contain one control statement, such as LOOP or WHILE, or one SQL DDL, DML, or DCL statement, including dynamic SQL. Some statements are not allowed, including:
- Any declaration (local variable, cursor, condition, or condition handler) statement
- A cursor statement (OPEN, FETCH, or CLOSE)
A compound statement stored procedure body consists of a BEGIN-END statement enclosing a set of declarations and statements, including:
- Local variable declarations
- Cursor declarations
- Condition declarations
- Condition handler declaration statements
- Control statements
- SQL DML, DDL, and DCL statements supported by stored procedures, including dynamic SQL
- Multistatement requests (including dynamic multistatement requests) delimited by the keywords BEGIN REQUEST and END REQUEST
Compound statements can also be nested.