Entering content frame

Routine 

The part of the CREATE DBPROC statement, CREATE TRIGGER statement, or CREATE FUNCTION statement described as the routineis the implementation of the database procedure, the trigger, or the database function. The routine comprises optional variable declarations and statements.

Syntax

<routine> ::= [<local_variables>] <statement_list>;

<local_variables> ::=VAR <local_variable_list>;
<local_variable_list> ::= <local_variable> | <local_variable_list>; <local_variable>
<local_variable> ::= <variable_name> <data_type>
<variable_name> ::= <identifier>

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

identifier, data_type, statement

Explanation

The statements below referring to database procedures are also true for triggers and database functions.

Variables

The local variables of the database procedure must be declared explicitly by specifying a data type before they are used. Only BOOLEAN, CHAR[ACTER], DATE, FIXED, FLOAT, INT[EGER], NUMBER, REAL, SMALLINT, TIME, TIMESTAMP, and VARCHAR are permitted as data types data types. Once they have been declared, the variables can be used in any SQL and other statements.

Every database procedure has the variables $RC, $ERRMSG, and $COUNT implicitly.

The $RC variable returns a numeric error code after an SQL statement has been executed. The value 0 means that the SQL statement was successfully executed.
In parallel with $RC, the $ERRMSG variable returns an explanation of the error containing a maximum of 80 characters.
The number of lines processed in an SQL statement is indicated by the $COUNT variable.

Variables can be assigned a value with the assignment_statement (see statement).

Restrictions

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

 

Leaving content frame