DB2 Version 9.7 for Linux, UNIX, and Windows

Declaring local variables of the anchored data type

Declaring local variables or parameters of the anchored data type is a task that you would perform whenever it is necessary that the data type of the variable or parameter remain consistent with the data type of the object to which it is anchored.

Before you begin

The object of the data type that the variable will be anchored to must be defined.

Procedure

  1. Formulate a DECLARE statement
    1. Specify the name of the variable.
    2. Specify the ANCHOR DATA TYPE TO clause.
    3. Specify the name of the object that is of the data type that the variable is to be anchored.
  2. Execute the DECLARE statement from a supported DB2® interface.

Results

If the DECLARE statement executes successfully, the variable is defined in the database with the specified anchor data type.

Example

The following is an example of an anchored data type declaration in which a variable named v1 is anchored to the data type of a column named c1 in a table named emp:
DECLARE v1 ANCHOR DATA TYPE TO emp.c1;

What to do next

Once the variable is defined it can be assigned a value, be referenced, or passed as a parameter to routines.