SQL$HELP_OLD72.HLB  —  GET_ENVIRONMENT
    Loads values defined by OpenVMS DCL symbols or logical names and
    SQL session values into locally declared SQL variables.

1  –  Environment

    You can use the GET ENVIRONMENT statement in interactive SQL
    only.

2  –  Format

  GET ENVIRONMENT -+--------------------------------+--+
                   +-> ( --> getenv-options --> ) --+  |
   +------------------------ <-------------------------+
   +---+- : <variable> = identifier -+------------------->
       +------------ , <-------------+

  getenv-options =

  --+-+--> SESSION -+-+->
    | +--> TRACE ---+ |
    +------  , <------+

3  –  Arguments

3.1  –  SESSION

    Directs GET ENVIRONMENT to return selected interactive SQL
    session options. These options can be used to save and restore
    session state during the execution of an SQL script.

3.2  –  TRACE

    Displays the translated string value prior to being converted
    to the data type of the variable. This can assist in diagnosing
    data conversion errors. The display will indicate if the result
    was derived from a local symbol, global symbol, logical name, or
    session value. For example:

    SQL> GET ENVIRONMENT (TRACE)
    cont>     :xx indicator :xx_ind = XX;
    01: XX = XX "--" (Local)
    %RDB-E-ARITH_EXCEPT, truncation of a numeric value at runtime
    -COSI-F-INPCONERR, input conversion error

    The following table shows the associated SET command which will
    accept the output from GET ENVIRONMENT (SESSION). These commands
    allow application to re-establish the environment after using SET
    commands within an SQL script. Refer to the listed SET command
    for details of the string value that will be returned from GET
    ENVIRONMENT.

    Table 1-3 GET ENVIRONMENT session keywords

    SESSION Keyword        Associated SET command

    DEFAULT_CATALOG        SET CATALOG
    CONSTRAINT_MODE        SET DEFAULT CONSTRAINT MODE
    CHARACTER_LENGTH       SET CHARACTER LENGTH
    COMPOUND_              SET COMPOUND TRANSACTION
    TRANSACTIONS
    DATE_FORMAT            SET DEFAULT DATE FORMAT
    DEFAULT_CONSTRAINT_    SET DEFAULT CONSTRAINT MODE
    MODE
    DIALECT                SET DIALECT
    HOLD_CURSORS           SET HOLD CURSOR
    NULL_STRING            SET DISPLAY NULL STRING
    QUIET_COMMIT           SET QUIET COMMIT
    QUOTING_RULES          SET QUOTING RULES
    KEYWORD_RULES          SET KEYWORD RULES
    DEFAULT_SCHEMA         SET SCHEMA
    DEFAULT_ALIAS          SET ALIAS

4  –  Examples

    Example 1: Using the GET ENVIRONMENT Statement

    $ emp_id = "00164"
    $ SQL$
    SQL> ATTACH 'FILENAME MF_PERSONNEL';
    SQL> DECLARE :e CHAR(5);
    SQL> GET ENVIRONMENT :e = emp_id;
    SQL> SELECT last_name, first_name FROM employees WHERE employee_id = :e;
     LAST_NAME        FIRST_NAME
     Toliver          Alvin
    1 row selected
    SQL> ROLLBACK;

    Example 2: Using the SESSION option

    This example uses the SESSION option to save the DIALECT and
    restore it upon completion of the SQL script.

    SQL> declare :Rdb_DIALECT char(10);
    SQL> get environment (session) :Rdb_DIALECT = DIALECT;
    SQL> set dialect 'SQL92';
    SQL> -- get SQL92 semantics for UNIQUE constrain
    SQL> create table T (a integer unique);
    SQL> set dialect :Rdb_DIALECT;
    SQL> undeclare :Rdb_DIALECT;
Close Help