Entering content frame

statement 

statement is a syntax element that is used in a routine. The statements specified in the statement syntax description can be used to define a database procedure (see CREATE DBPROC statement), ar trigger (see CREATE TRIGGER statement), or a database function (siehe CREATE FUNCTION statement).

Syntax

<statement> ::= BEGIN <statement_list> END | BREAK | CONTINUE | CONTINUE EXECUTE
| <if_statement> | <while_statement> | <assignment_statement> | <case_statement>
| RETURN [<expression>]
| STOP (<expression> [,<expression>] )
| TRY <statement_list>; CATCH <statement>
| <routine_sql_statement>

<statement_list> ::= <statement> | <statement_list> ; <statement>

<if_statement> ::= IF <search_condition> THEN <statement> [ELSE <statement>]
<while_statement> ::= WHILE <search_condition> DO <statement>
<assignment_statement> ::= [SET] <variable_name> = <expression>
<case_statement> ::= <simple_case_statement> | <searched_case_statement>

<routine_sql_statement> ::=
  <call_statement> | <close_statement> | <create_table_temp> | <drop_table_temp>
| <declare_cursor_statement> | <delete_statement> | <fetch_statement>
| <insert_statement> | <lock_statement>
| <select_statement> | <named_select_statement> | <single_select_statement>
| <subtrans_statement> | <update_statement>

<variable_name> ::= <identifier>

<create_table_temp> :: = <create_table_statement> for creating temporary tables, that is, the table_name in the CREATE TABLE statement must have the format TEMP.<identifier>.

<drop_table_temp> ::= DROP TABLE TEMP.<identifier>

expression, search_condition, simple_case_statement, searched_case_statement, call_statement, close_statement, create_table_statement, declare_cursor_statement; delete_statement, fetch_statement, insert_statement, lock_statement, select_statement, named_select_statement, single_select_statement, subtrans_statement, update_statement, identifier

Explanation

Variables specified in a routine can be assigned a value with the assignment statement.

Control Structures

The IF statement (if_statement) first evaluates the search condition. If this is fulfilled, the statement specified in the THEN branch is executed. Otherwise, the statement in the ELSE branch (if defined) is executed.

The WHILE statement (while_statement) enables statements to be repeated in response to certain conditions. The statement is executed as long as the specified search condition is true. The condition is checked, in particular, before the statement is executed for the first time. This means that the statement may not be executed at all. By specifying BREAK, you can exit the loop straight away, without checking the condition. If CONTINUE is specified in the loop, the condition is re-evaluated immediately and the loop is processed again or exited, depending on the result.

The CASE statement (case_statement) allows the conditional execution of a statement, dependent on search conditions or the equality of operators. There are simple and general CASE statements.

RETURN

CREATE DBPROC and CREATE TRIGGER statement: Specifying RETURN enables you to exit the surrounding database procedure immediately without causing errors.

CREATE FUNCTION statement: Specifying RETURN <expression> enables you to exit the database function while specifying the function value <expression> at the same time.

Troubleshooting

If an SQL error occurs in the statement list between TRY and CATCH, the system branches directly to the statement that follows CATCH. The actual troubleshooting routine can be programmed in this statement. If CONTINUE EXECUTE is executed here, the system jumps directly to the point after the statement that triggered the error.

The database procedure is interrupted immediately when the STOP function is invoked. The value of the first parameter of the STOP function is the return or error message that the application receives as the result of the database procedure call. An error text can also be returned.

SQL Statements (routine_sql_statement)

The tables in the SQL statements (routine_sql_statement) of the database procedure must always be complete, that is, with the owner specified. In the case of SELECT statements, a full statement of the table name in the FROM clause is sufficient.

Restrictions

The statement list (statement_list) must not contain more than 255 SQL statements.

The length of an SQL statement (routine_sql_statement) must not exceed approximately 8 KB.

 

Leaving content frame