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)0[m[1;4mDECLARE[m[1m qqwq> <table-name> qwq> [1;4mTABLE[m[1m qqk [m [1m mq> <view-name> qqj x [m [1m lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1m mq> ( qwwq> declare-col-definition qwwq> ) qq> [m [1m xmq> table-constraint qqqqqqqjx [m [1m mqqqqqqqqqq , <qqqqqqqqqqqqqqqj [m (B)0[m[1mdeclare-col-definition = [m [1m [m [1mqq> <column-name> qq> data-type qwwqqqqqqqqqqqqqqqqqqqqqqqqwwq> [m [1m xtq> col-constraint qqqqqqux [m [1m xmq> sql-and-dtr-clause qqjx [m [1m mqqqqqqqqqqq <qqqqqqqqqqqqqj [m [1m [m (B)0[m[1mdata-type = [m [1m [m [1m qwq> char-data-types qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq> [m [1m tq> [1;4mTINYINT[m[1m qqqqqqqqqqqqqqwqqqqqwqqqqqqqqqqqqwqqqqqqqqqqqqqqqu [m [1m tq> [1;4mSMALLINT[m[1m qqqqqqqqqqqqqu mq> ( <n> ) qj x [m [1m tq> [1;4mINTEGER[m[1m qqqqqqqqqqqqqqu x [m [1m tq> [1;4mBIGINT[m[1m qqqqqqqqqqqqqqqu x [m [1m tq> [1;4mFLOAT[m[1m qqqqqqqqqqqqqqqqj x [m [1m tq> [1;4mNUMBER[m[1m qwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqu [m [1m x mq> ( qwq> <p> qwqwqqqqqqqqqqwq> ) j x [m [1m x mq> * qqqj mq> , <d> qj x [m [1m tq> [1;4mLIST[m[1m [1;4mOF[m[1m [1;4mBYTE[m[1m [1;4mVARYING[m[1m qqwqqqqqqqqqqqqwqqwqqqqqqqqqqqqqqwqqu [m [1m x mq> ( <n> ) qj tq> [1;4mAS[m[1m [1;4mBINARY[m[1m qu x [m [1m x mq> [1;4mAS[m[1m [1;4mTEXT[m[1m qqqj x [m [1m tq> [1;4mDECIMAL[m[1m qwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqu [m [1m tq> [1;4mNUMERIC[m[1m qjmq> ( qq> <n> wqqqqqqqqqqwq> ) j x [m [1m x mq> , <n> qj x [m [1m tq> [1;4mREAL[m[1m qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mDOUBLE[m[1m [1;4mPRECISION[m[1m qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m mq> date-time-data-types qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1m [m (B)0[m[1mchar-data-types = [m [1m [m [1mqwq> [1;4mCHAR[m[1m qqqqqqqqqqqqqwwqqqqqqqqqqqqwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwq>[m [1m tq> [1;4mCHARACTER[m[1m qqqqqqqqumq> ( <n> ) qjmq> [1;4mCHARACTER[m[1m [1;4mSET[m[1m char[m-[1mset-name qj x [m [1mtq> [1;4mCHAR[m[1m [1;4mVARYING[m[1m qqqqqu[m [1m [m [1mx [m [1mtq> [1;4mCHARACTER[m[1m [1;4mVARYING[m[1m j[m [1mx [m [1mtq> [1;4mVARCHAR[m[1m qqw>[m [1m( <n> ) qqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqu [m [1mtq> [1;4mVARCHAR2[m[1m qj[m [1m mq> [1;4mCHARACTER[m[1m [1;4mSET[m[1m char-set-name qj [m [1mx[m [1m tq> [1;4mLONG[m[1m [1;4mVARCHAR[m[1m qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mNCHAR[m[1m qqqqqqqqqqqqqqwqwqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mNATIONAL[m[1m [1;4mCHAR[m[1m qqqqqqu mq> ( <n> ) qj [m [1m [m [1mx [m [1m tq> [1;4mNATIONAL[m[1m [1;4mCHARACTER[m[1m qj [m [1m [m [1mx [m [1m tq> [1;4mNCHAR[m[1m [1;4mVARYING[m[1m qqqqqqqqqqqqqqwqwqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqu[m [1m tq> [1;4mNATIONAL[m[1m [1;4mCHAR[m[1m [1;4mVARYING[m[1m qqqqqqu mq> ( <n> ) qj [m [1m [m [1mx [m [1m tq> [1;4mNATIONAL[m[1m [1;4mCHARACTER[m[1m [1;4mVARYING[m[1m qj [m [1m [m [1mx [m [1mtq> [1;4mRAW[m[1m q> ( <n> ) q[mqqq[1mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu[m [1mmq> [1;4mLONG[m[1m qwqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1mmq> [1;4mRAW[m[1m qj[m (B)0[m[1mdate-time-data-types = [m [1m [m [1mqqwq> [1;4mDATE[m[1m qwqqqqqqqqqqwqqqqqqqqqqqqqqqqqwqq> [m [1m x tq> [1;4mANSI[m[1m qu x [m [1m x mq> [1;4mVMS[m[1m qqqj x [m [1m tq> [1;4mTIME[m[1m qqq> frac qqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mTIMESTAMP[m[1m qq> frac qqqqqqqqqqqqqqqqu [m [1m mq> [1;4mINTERVAL[m[1m qqq> interval-qualifier qqj [m [1m [m (B)0[m[1mfrac = [m [1m [m [1mqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqwq> [m [1m mqq> ( <numeric-literal> ) qj [m [1m [m (B)0[m[1minterval-qualifier = [m [1m [m [1mqqwq> [1;4mYEAR[m[1m qqq> prec qqwqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqwq> [m [1m x mq> [1;4mTO[m[1m [1;4mMONTH[m[1m qj x [m [1m tq> [1;4mMONTH[m[1m qq> prec qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mDAY[m[1m qqqq> prec qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m x mq> [1;4mTO[m[1m qwq> [1;4mHOUR[m[1m qqqqqqqqqqqqqqqu [m [1m x tq> [1;4mMINUTE[m[1m qqqqqqqqqqqqqu [m [1m x mq> [1;4mSECOND[m[1m q> frac qqqqqu [m [1m tq> [1;4mHOUR[m[1m qqq> prec qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m x mq> [1;4mTO[m[1m qwq> [1;4mMINUTE[m[1m qqqqqqqqqqqqqu [m [1m x mq> [1;4mSECOND[m[1m q> frac qqqqqu [m [1m tq> [1;4mMINUTE[m[1m q> prec qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m x mq> [1;4mTO[m[1m [1;4mSECOND[m[1m qqqqqq> frac qqqqqu [m [1m mq> [1;4mSECOND[m[1m q> seconds-prec qqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1m [m (B)0[m[1mprec = [m [1m [m [1mqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqwq> [m [1m mqq> ( <numeric-literal> ) qj [m [1m [m (B)0[m[1mseconds-prec = [m [1m [m [1mqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq> [m [1m mq> ( <numeric-literal-1> qqqk x [m [1m lqqqqqqqqqqqqqqqqqqqqqqqqqj x [m [1m mwqqqqqqqqqqqqqqqqqqqqqqqqqqwq> ) qqj [m [1m m> , <numeric-literal-2> qqj [m [1m [m (B)0[m[1mcol-constraint= [m [1m [m [1mqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqk [m [1m m> [1;4mCONSTRAINT[m[1m <constraint-name> qj x [m [1m lqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqj [m [1m tq> [1;4mPRIMARY[m[1m [1;4mKEY[m[1m qqqqqqqqqqqqqqqqqk [m [1m tq> [1;4mUNIQUE[m[1m qqqqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mNOT[m[1m [1;4mNULL[m[1m qqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mNULL[m[1m qqqqqqqqqqqqqqqqqqqqqqqqu[m [1m tq> [1;4mCHECK[m[1m (predicate) qqqqqqqqqqqu [m [1m tq> references-clause qqqqqqqqqqqu [m [1m mqqqqqqqqqqqqqqq>qqqqqqqqqqqqqqqqu [m [1m lqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqj [m [1m mqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq> [m [1m mqq> constraint-attributes qqj [m (B)0[m[1mconstraint-attributes = [m [1m [m [1mqwq> [1;4mDEFERRABLE[m[1m qqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwq> [m [1m x mq> [1;4mINITIALLY[m[1m wq> [1;4mIMMEDIATE[m[1m qqwj x [m [1m x mq> [1;4mDEFERRED[m[1m qqqj x [m [1m tq> [1;4mNOT[m[1m [1;4mDEFERRABLE[m[1m qqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqu [m [1m x mq> [1;4mINITIALLY[m[1m [1;4mIMMEDIATE[m[1m qqj x [m [1m tq> [1;4mINITIALLY[m[1m [1;4mIMMEDIATE[m[1m qqqqwqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqu [m [1m x tq> [1;4mDEFERRABLE[m[1m qqqqqu x [m [1m x mq> [1;4mNOT[m[1m [1;4mDEFERRABLE[m[1m qj x [m [1m mq> [1;4mINITIALLY[m[1m [1;4mDEFERRED[m[1m qqqqqwqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqj [m [1m mq> [1;4mDEFERRABLE[m[1m qqqqqj [m (B)0[m[1msql-and-dtr-clause = [m [1m [m [1mqwq> [1;4mQUERY[m[1m [1;4mHEADER[m[1m IS qw> <quoted-string> wqqqqqqqqqqqqqqqqqqqwq> [m [1m x mqqqqqq / <qqqqqqqqj x [m [1m tq> [1;4mEDIT[m[1m [1;4mSTRING[m[1m IS <quoted-string> qqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m x x [m [1m tq> [1;4mQUERY[m[1m [1;4mNAME[m[1m FOR qwq> DTR qqqqqqqqwq> IS <quoted-string> qu [m [1m x mq> DATATRIEVE qj x [m [1m mq> [1;4mDEFAULT[m[1m [1;4mVALUE[m[1m FOR qwq> DTR qqqqqqqqwq> IS literal[m [1m qqqqj [m [1m mq> DATATRIEVE qj [m [1m [m (B)0[m[1mtable-constraint = [m [1m [m [1mqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqk [m [1m mq> [1;4mCONSTRAINT[m[1m <constraint-name> qqqj x [m [1m lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1m mqq> table-constraint-clause qqqqqqqqqqqqqqk [m [1m lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1m mqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqq> [m [1m mq> constraint-attributes qqj [m [1m [m (B)0[m[1mtable-constraint-clause = [m [1m [m [1mqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq>[m [1m tq> [1;4mPRIMARY[m[1m [1;4mKEY[m[1m q> ( qw> <column-name> wq> ) qqu [m [1m x mqqqqqqq , <qqqqqj x [m [1m tq> [1;4mUNIQUE[m[1m q> ( qw> <column-name> wq> ) qqqqqqqu [m [1m x mqqqqqqq , <qqqqqj x [m [1m tq> [1;4mCHECK[m[1m (predicate) qqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m mq> [1;4mFOREIGN[m[1m [1;4mKEY[m[1m q> ( qw> <column-name> wq> ) k x [m [1m mqqqqqqq , <qqqqqj x x [m [1m lqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqj x [m [1m mq> references-clause qqqqqqqqqq>qqqqqqqqqqqqj [m [1m [m
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