Flow of Control

The persistent stored module facility of SQL provides a method to encode complex algorithm using well-known programming features.

control_statement:
     CALL func_ref
   | CALL routine_name '(' argument_list ')'
   | while_statement
   | if_statement
   | case_statement
   | RETURN return_value

case_statement:
    CASE scalar_exp when_statement ... [ ELSE procedure_statement_list ] END CASE
  | CASE when_search_statement ... [ ELSE procedure_statement_list ] END CASE

when_statement: WHEN scalar_exp THEN procedure_statement_list

when_search_statement: WHEN search_condition THEN procedure_statement_list

if_statement: IF search_condition THEN procedure_statement_list if_opt_else END IF

if_opt_else:
      /* empty */
   | ELSE procedure_statement_list
   | ELSEIF search_condition THEN procedure_statement_list if_opt_else

while_statement:
    [ ident ':' ] WHILE search_condition DO procedure_statement_list END WHILE [ ident ]

return_statement: RETURN return_value

return_value:
      select_no_parens_orderby
    | search_condition
    | TABLE '(' select_no_parens_orderby ')'
    | NULL
```