SQL$HELP72.HLB  —  DECLARE  TABLE
    Explicitly declares a table or view definition in a program. For
    tables named in a DECLARE TABLE statement, SQL does not check the
    schema to compare the definition with the explicit declaration.

    An explicit table declaration is useful to:

    o  Document the definition in the source code of the program

    o  Allow references to tables that do not exist when SQL
       precompiles the program, including:

       -  Tables created in other modules of the program

       -  Tables created dynamically

    o  Improve precompiler performance because SQL does not need to
       attach to the schema to retrieve the table definition

    o  Make it easier to check that the declaration correctly
       corresponds to a host structure the program uses to hold
       values from or for the table

    o  Declare only a subset of columns contained in the schema
       definition of the table if the program needs to use only some
       of the columns

1  –  Environment

    You can use the DECLARE TABLE statement:

    o  Embedded in host language programs to be precompiled

    o  In a context file

    o  As part of the DECLARE section in an SQL module

2  –  Format

  (B)0DECLARE qqwq> <table-name> qwq> TABLE qqk          
            mq> <view-name> qqj           x          
    lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj          
    mq> ( qwwq> declare-col-definition qwwq> ) qq>   
           xmq> table-constraint qqqqqqqjx           
           mqqqqqqqqqq , <qqqqqqqqqqqqqqqj           

  (B)0declare-col-definition =                                        
                                                                  
  qq> <column-name> qq> data-type qwwqqqqqqqqqqqqqqqqqqqqqqqqwwq> 
                                   xtq> col-constraint qqqqqqux   
                                   xmq> sql-and-dtr-clause qqjx   
                                   mqqqqqqqqqqq <qqqqqqqqqqqqqj   
                                                                  

  (B)0data-type =                                                           
                                                                        
   qwq> char-data-types qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq>   
    tq> TINYINT qqqqqqqqqqqqqqwqqqqqwqqqqqqqqqqqqwqqqqqqqqqqqqqqqu      
    tq> SMALLINT qqqqqqqqqqqqqu     mq> ( <n> ) qj               x      
    tq> INTEGER qqqqqqqqqqqqqqu                                  x      
    tq> BIGINT qqqqqqqqqqqqqqqu                                  x      
    tq> FLOAT qqqqqqqqqqqqqqqqj                                  x      
    tq> NUMBER qwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqu      
    x           mq> ( qwq> <p> qwqwqqqqqqqqqqwq> ) j             x      
    x                  mq> * qqqj mq> , <d> qj                   x      
    tq> LIST OF BYTE VARYING qqwqqqqqqqqqqqqwqqwqqqqqqqqqqqqqqwqqu      
    x                          mq> ( <n> ) qj  tq> AS BINARY qu  x      
    x                                          mq> AS TEXT qqqj  x      
    tq> DECIMAL qwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqu      
    tq> NUMERIC qjmq> ( qq> <n> wqqqqqqqqqqwq> ) j               x      
    x                           mq> , <n> qj                     x      
    tq> REAL qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu      
    tq> DOUBLE PRECISION qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu      
    mq> date-time-data-types qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj      
                                                                         

  (B)0char-data-types =                                                      
                                                                         
  qwq> CHAR qqqqqqqqqqqqqwwqqqqqqqqqqqqwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwq>
   tq> CHARACTER qqqqqqqqumq> ( <n> ) qjmq> CHARACTER SET char-set-name qj x  
   tq> CHAR VARYING qqqqqu                                                 x  
   tq> CHARACTER VARYING j                                                 x  
   tq> VARCHAR qqw> ( <n> ) qqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqu  
   tq> VARCHAR2 qj             mq> CHARACTER SET char-set-name qj          x
   tq> LONG VARCHAR  qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu  
   tq> NCHAR qqqqqqqqqqqqqqwqwqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu 
   tq> NATIONAL CHAR qqqqqqu mq> ( <n> ) qj                                x  
   tq> NATIONAL CHARACTER qj                                               x  
   tq> NCHAR VARYING qqqqqqqqqqqqqqwqwqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqu
   tq> NATIONAL CHAR VARYING qqqqqqu mq> ( <n> ) qj                        x  
   tq> NATIONAL CHARACTER VARYING qj                                       x  
   tq> RAW q> ( <n> ) qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
   mq> LONG qwqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj  
             mq> RAW qj

  (B)0date-time-data-types =                        
                                                
  qqwq> DATE qwqqqqqqqqqqwqqqqqqqqqqqqqqqqqwqq> 
    x         tq> ANSI  qu                 x    
    x         mq> VMS qqqj                 x    
    tq> TIME qqq> frac qqqqqqqqqqqqqqqqqqqqu    
    tq> TIMESTAMP qq> frac qqqqqqqqqqqqqqqqu    
    mq> INTERVAL qqq> interval-qualifier qqj    
                                                

  (B)0frac =                            
                                    
  qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqwq> 
    mqq> ( <numeric-literal> ) qj   
                                    

  (B)0interval-qualifier =                                       
                                                             
  qqwq> YEAR qqq> prec qqwqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqwq> 
    x                    mq> TO MONTH qj                 x   
    tq> MONTH qq> prec qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu   
    tq> DAY qqqq> prec qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu   
    x                    mq> TO qwq> HOUR qqqqqqqqqqqqqqqu   
    x                            tq> MINUTE qqqqqqqqqqqqqu   
    x                            mq> SECOND q> frac qqqqqu   
    tq> HOUR qqq> prec qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu   
    x                    mq> TO qwq> MINUTE qqqqqqqqqqqqqu   
    x                            mq> SECOND q> frac qqqqqu   
    tq> MINUTE q> prec qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu   
    x                    mq> TO SECOND qqqqqq> frac qqqqqu   
    mq> SECOND q> seconds-prec qqqqqqqqqqqqqqqqqqqqqqqqqqj   
                                                             

  (B)0prec =                            
                                    
  qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqwq> 
    mqq> ( <numeric-literal> ) qj   
                                    

  (B)0seconds-prec =                                
                                                
  qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq> 
    mq> ( <numeric-literal-1> qqqk         x    
       lqqqqqqqqqqqqqqqqqqqqqqqqqj         x    
       mwqqqqqqqqqqqqqqqqqqqqqqqqqqwq> ) qqj    
        m> , <numeric-literal-2> qqj            
                                                

  (B)0col-constraint=                           
                                            
  qqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqk  
      m> CONSTRAINT <constraint-name> qj x  
    lqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqj  
    tq> PRIMARY KEY qqqqqqqqqqqqqqqqqk      
    tq> UNIQUE qqqqqqqqqqqqqqqqqqqqqqu      
    tq> NOT NULL qqqqqqqqqqqqqqqqqqqqu      
    tq> NULL qqqqqqqqqqqqqqqqqqqqqqqqu
    tq> CHECK (predicate) qqqqqqqqqqqu      
    tq> references-clause qqqqqqqqqqqu      
    mqqqqqqqqqqqqqqq>qqqqqqqqqqqqqqqqu      
    lqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqj      
    mqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq>  
         mqq> constraint-attributes qqj     

  (B)0constraint-attributes =                                            
                                                                     
  qwq> DEFERRABLE qqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwq>  
   x                           mq> INITIALLY wq> IMMEDIATE qqwj x    
   x                                         mq> DEFERRED qqqj  x    
   tq> NOT DEFERRABLE qqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqu    
   x                           mq> INITIALLY IMMEDIATE qqj      x    
   tq> INITIALLY IMMEDIATE qqqqwqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqu    
   x                           tq> DEFERRABLE qqqqqu            x    
   x                           mq> NOT DEFERRABLE qj            x    
   mq> INITIALLY DEFERRED qqqqqwqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqj    
                               mq> DEFERRABLE qqqqqj                 

  (B)0sql-and-dtr-clause =                                             
                                                                   
  qwq> QUERY HEADER IS qw> <quoted-string> wqqqqqqqqqqqqqqqqqqqwq> 
   x                    mqqqqqq / <qqqqqqqqj                   x   
   tq> EDIT STRING IS <quoted-string> qqqqqqqqqqqqqqqqqqqqqqqqqu   
   x                                                           x   
   tq> QUERY NAME FOR qwq> DTR qqqqqqqqwq> IS <quoted-string> qu   
   x                   mq> DATATRIEVE qj                       x   
   mq> DEFAULT VALUE FOR qwq> DTR qqqqqqqqwq> IS literal   qqqqj  
                          mq> DATATRIEVE qj                        
                                                                   

  (B)0table-constraint =                               
                                                   
  qqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqk    
     mq> CONSTRAINT <constraint-name> qqqj    x    
   lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj    
   mqq> table-constraint-clause qqqqqqqqqqqqqqk    
   lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj    
   mqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqq> 
       mq> constraint-attributes qqj               
                                                   

  (B)0table-constraint-clause =                           
                                                      
  qwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq>
   tq> PRIMARY KEY q> ( qw> <column-name> wq> ) qqu   
   x                     mqqqqqqq , <qqqqqj       x   
   tq> UNIQUE q> ( qw> <column-name> wq> ) qqqqqqqu   
   x                mqqqqqqq , <qqqqqj            x   
   tq> CHECK (predicate) qqqqqqqqqqqqqqqqqqqqqqqqqu   
   mq> FOREIGN KEY q> ( qw> <column-name> wq> ) k x   
                         mqqqqqqq , <qqqqqj     x x   
     lqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqj x   
     mq> references-clause qqqqqqqqqq>qqqqqqqqqqqqj   
                                                      

3  –  Arguments

3.1  –  character-set-name

    A valid character set name. See the Oracle Rdb SQL Reference
    Manual for more information on character sets.

3.2  –  col-constraint

    A column constraint. See the CREATE TABLE statement for more
    information about column constraints.

3.3  –  column-name

    The name of the column you want to define.

3.4  –  data-type

    The data type of the column you want to define. See the Data_
    Types HELP topic for more information on data types.

3.5  –  date-time-data-types

    Data types for dates, times, and intervals. See  the Data_Types
    HELP topic for more information on date-time data types.

3.6  –  declare-col-definition

    The definition for a column in the table. The column definition
    must correspond to the table definition in the schema.

    See the CREATE TABLE statement for more information about column
    definitions.

    However, you cannot refer to domain names in a DECLARE TABLE
    statement. For tables whose definitions refer to domain names,
    you must substitute the data type and size of the domain for the
    domain name.

3.7  –  frac

    Precision specifications for date-time data types. See the Data_
    Types HELP topic for more information.

3.8  –  interval-qualifier

    Precision specifications for date-time data types. See the Data_
    Types HELP topic for more information.

3.9  –  prec

    Precision specifications for date-time data types. See the Data_
    Types HELP topic for more information.

3.10  –  references-clause

    See the CREATE TABLE statement for more information.

3.11  –  seconds-prec

    Precision specifications for date-time data types. See the Data_
    Types HELP topic for more information.

3.12  –  sql-and-dtr-clause

    Optional SQL and DATATRIEVE formatting clause. See the DATATRIEVE
    HELP topic for more information about formatting clauses.

3.13  –  table-name

    The name of the table definition you want to declare.

3.14  –  view-name

    The name of the view definition you want to declare.

3.15  –  table-constraint

    A constraint definition that applies to the whole table. See
    the CREATE TABLE statement for more information about specifying
    table constraints.

4  –  Examples

    Example 1: Declaring the table EMPLOYEES in a COBOL program

    EXEC SQL
    DECLARE EMPLOYEES TABLE
        (EMPLOYEE_ID                      CHAR (5)
           CONSTRAINT     EMP_EMPLOYEE_ID_NOT_NULL
           NOT NULL,
         LAST_NAME                        CHAR (14),
         FIRST_NAME                       CHAR (10),
         MIDDLE_INITIAL                   CHAR (1),
         ADDRESS_DATA_1                   CHAR (25),
         ADDRESS_DATA_2                   CHAR (25),
         CITY                             CHAR (20),
         STATE                            CHAR (2),
         POSTAL_CODE                      CHAR (5),
         SEX                              CHAR (1),
           CONSTRAINT     EMP_SEX_VALUES
           CHECK          (
                          SEX IN ('M', 'F') OR SEX IS NULL
                          ),
         BIRTHDAY                         DATE ,
         STATUS_CODE                      CHAR (1)
           CONSTRAINT     EMP_STATUS_CODE_VALUES
           CHECK          (
                          STATUS_CODE IN ('0', '1', '2')
                          OR STATUS_CODE IS NULL
                          )
         )
    END_EXEC
Close Help