DEFINE
Use the DEFINE statement to declare local variables that an SPL routine uses, or to declare global variables that can be shared by several SPL routines.
Syntax
Element | Description | Restrictions | Syntax |
---|---|---|---|
column | Column name | Must already exist in the table or view | Identifier |
data_type | Type of SPL_var | See Declaring Global Variables | Data Type |
distinct_type | A distinct type | Must already be defined in the database | Data Type |
opaque_type | An opaque type | Must already be defined in the database | Data Type |
SPL_var | New SPL variable | Must be unique within statement block | Identifier |
synonym, table, view | Name of a table, view, or synonym | Synonym and the table or view to which it points must exist when DEFINE is issued | Identifier |
Usage
The DEFINE statement is not an executable statement. The DEFINE statement must appear after the routine header and before any other statements. If you declare a local variable (by using DEFINE without the GLOBAL keyword), its scope of reference is the statement block in which it is defined. You can use the variable within the statement block. Another variable outside the statement block with a different definition can have the same name.
A variable with the GLOBAL keyword is global in scope and is available outside the statement block and to other SPL routines. Global variables can be any built-in data type except BIGSERIAL, BLOB, BYTE, CLOB, SERIAL, SERIAL8, or TEXT. Local variables can be any built-in data type except BIGSERIAL, BYTE, SERIAL, SERIAL8, or TEXT. If column is of the BIGSERIAL, SERIAL, or SERIAL8 data type, declare a BIGINT, INT, or INT8 variable to store its value.