SQL$HELP_OLD72.HLB  —  DECLARE  Variable
    Declares variables that you can use in interactive and dynamic
    SQL for invoking stored procedures and for testing procedures in
    modules or embedded SQL programs. For information on declaring
    variables in compound statements, see the Compound_Statement HELP
    topic.

1  –  Environment

    You can use the DECLARE statement:

    o  In interactive SQL

    o  In dynamic SQL as a statement to be dynamically executed

2  –  Format

  DECLARE -+-> :<variable-name> +--+---------------+-+
           +-------- , <--------+  +--> CONSTANT --+ |
                                   +--> UPDATABLE -+ |
  +--------------------------------------------------+
  +-+-> data-type ----+-+--------------------+------->
    +-> <domain-name> + +-> default-clause  -+

  default-clause =

  --+-> DEFAULT --+--+--> date-time-literal -+----->
    +->   = ------+  +--> interval-literal  -+
                     +--> numeric-literal  --+
                     +--> string-literal  ---+
                     +--> : <variable-name> -+

3  –  Arguments

3.1  –  CONSTANT

    Syntax options:

    CONSTANT | UPDATABLE

    CONSTANT changes the variable into a declared constant that
    cannot be updated. If you specify CONSTANT, you must also have
    specified the DEFAULT clause to ensure the variable has a value.
    CONSTANT also indicates that the variable cannot be used as
    the target of an assignment or be passed as an expression to a
    procedure's INOUT or OUT parameter.

    UPDATABLE is the default and allows the variable to be modified.
    An update of a variable can occur due to a SET assignment, an
    INTO assignment (as part of an INSERT ... RETURNING, UPDATE ...
    RETURNING, or SELECT statement), or as a procedure's OUT or INOUT
    parameter on a CALL statement.

3.2  –  data-type

    Specifies the data type assigned to the variable. See the Data_
    Types HELP topic for more information on data types.

3.3  –  default-clause

    You can only use references to simple literal values and other
    declared variables as a default.

3.4  –  domain-name

    Specifies the domain name assigned to the variable. The domain
    supplies the data type and, for interactive SQL, the edit string
    of the variable.

    See the User_Supplied_Names HELP topic for more information on
    domain names.

3.5  –  variable-name

    Specifies the local variable.

4  –  Example

    Example 1: Declaring variables in interactive SQL

    SQL> DECLARE :X INTEGER;
    SQL> DECLARE :Y CHAR(10);
    SQL>
    SQL>  BEGIN
    cont>    SET :X = 100;
    cont>    SET :Y = 'Active';
    cont> END;
    SQL> PRINT :X, :Y ;
               X   Y
             100   Active
    SQL> SHOW VARIABLES;
    X                               INTEGER
    Y                               CHAR(10)

    Example 2: Using the values of SQLSTATE in an interactive SQL
    script

    The following simple script uses the named SQLSTATE variable with
    the SIGNAL statement to make the script easier to read.

    @SYS$LIBRARY:SQLSTATE
    set verify;
    begin
    signal :SQLSTATE_DATA_ASSIGN ('Error in assignment');
    end;

    When executed the output appears as shown below.

    SQL> begin
    cont> signal :SQLSTATE_DATA_ASSIGN ('Error in assignment');
    cont> end;
    %RDB-E-SIGNAL_SQLSTATE, routine "(unnamed)" signaled SQLSTATE "22005"
    -RDB-I-TEXT, Error in assignment
    SQL>
Close Help