Creates a domain definition. A domain defines the set of values, character set, collating sequence, and formatting clause that a column in a table can have. The CREATE DOMAIN statement specifies the set of values by associating a data type with a domain name. There are two ways to specify a domain definition: o With a domain name, data type, and any combination of the following optional clauses: - Default value - Stored name - Collating sequence - Formatting clauses such as EDIT STRING or QUERY HEADER o With the FROM clause and a repository path name that refers to a field already defined in the repository When the CREATE DOMAIN statement executes, SQL adds the domain definition to the database. If you attached to the database with the PATHNAME specification, the domain definition is also added to the repository. You can refer to a domain instead of an SQL data type in the CREATE and ALTER TABLE statements, and in formal parameter declarations in functions and procedures. If the domain has to change, you need only change that one domain definition (using the ALTER DOMAIN statement) to change all the tables. This ability makes it easier to keep applications consistent. A domain can be referenced in the following locations: o CREATE, ALTER and DROP DOMAIN statements o CREATE and ALTER TABLE statements as the data type for a column o CREATE and ALTER MODULE statements as the data type of a routine parameter, or the data type of declared variable o CREATE FUNCTION statement as the data type of a function parameter or function result o CREATE PROCEDURE statement as the data type of a procedure parameter o CREATE and ALTER SYNONYM statement as the base object for a synonym o as the datatype of a CAST expression o as a data type of a DECLARE variable statement in interactive SQL o as the source in the EDIT USING clause of the SELECT and PRINT statements in interactive SQL. The EDIT STRING is inherited from that domain.
1 – Environment
You can use the CREATE DOMAIN statement: o In interactive SQL o Embedded in host language programs to be precompiled o As part of a procedure in an SQL module o In dynamic SQL as a statement to be dynamically executed
2 – Format
(B)0[m[1;4mCREATE[m[1m [1;4mDOMAIN[m[1m qk [m [1mlqqqqqqqqqqqqqqj [m [1mtq> <domain-name> wqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwk [m [1mx mq> [1;4mSTORED[m[1m [1;4mNAME[m[1m IS <stored-name> qqqjx [m [1mxlqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1mxmwq> IS data-type qwqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqk [m [1mx mq> AS data-type qj mqq> [1;4mDEFAULT[m[1m value-expr qqqqqj x [m [1mx lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1mx mqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqk [m [1mx tq> [1;4mCOLLATING[m[1m [1;4mSEQUENCE[m[1m IS <collation-name> qqu x [m [1mx mq> [1;4mNO[m[1m [1;4mCOLLATING[m[1m [1;4mSEQUENCE[m[1m qqqqqqqqqqqqqqqqqqqj x [m [1mx lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1mx mqwqqqqqqqqqqqqqqqqqqqqqqwqwqqqqqqqqqqqqqqqqqqqqqqqqwwq> [m [1mx mq> domain-constraint qj mw> sql-and-dtr-clause qwjx [m [1mx mqqqqqqqqq<qqqqqqqqqqqqj x [m [1mmq> [1;4mFROM[m[1m q> <path-name> wqqqqqqqqqqqqqqqqq>qqqqqqqqqqwqqqj [m [1m mq> [1;4mDATABASE[m[1m ALIAS <alias> qqj [m (B)0[m[1mdomain-name = [m [1m [m [1mqwqqqqqqqqqqqqqqqqqqqqqqqqqqqwq> <name-of-domain> qqq> [m [1m mqwq> <schema-name> qwq> . qj [m [1m [m [1m mq> <alias> qqqqqqqj [m [1m [m [1m [m [1m [m [1m [m (B)0[m[1mdata-type = [m [1m [m [1mqqwq> char-data-types qqqqqqqqqqqqqqqqqqqqqqqqqqqwqq> [m [1m tq> [1;4mTINYINT[m[1m qqqqqqqqqqqqqqwqqqqqwqqqqqqqqqqwqqqu [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;4mLIST[m[1m [1;4mOF[m[1m [1;4mBYTE[m[1m [1;4mVARYING[m[1m qj x [m [1m tq> [1;4mDECIMAL[m[1m qwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqu [m [1m tq> [1;4mNUMERIC[m[1m qjmq> ( q> <n> wqqqqqqqqqqwq> ) j x [m [1m x mq> , <n> qj x [m [1m tq> [1;4mFLOAT[m[1m qwqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m x mq> (<n>) qj x [m [1m tq> [1;4mREAL[m[1m qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mDOUBLE[m[1m [1;4mPRECISION[m[1m qqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m mq> date-time-data-types qqqqqqqqqqqqqqqqqqqqqqj [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[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[1mliteral = [m [1m [m [1mqqwq> numeric-literal qqqqwqqq> [m [1m tq> string-literal qqqqqu [m [1m tq> date-time-literal qqu [m [1m mq> interval-literal qqqj [m [1m [m (B)0[m[1mdomain-constraint = [m [1m [m [1mqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqq>[m [1m mq> [1;4mCHECK[m[1m ( predicate ) qwqqqqqqqqqqqqqqqqqqqqqqqqqqwj[m [1m [m [1mmq> constraint-attributes[m [1mqj[m [1m [m [1m [m (B)0[m[1msql-and-dtr-clause = [m [1m [m [1mqwq> [1;4mQUERY[m[1m [1;4mHEADER[m[1m IS qw> <quoted-string> wqqqqqqqqqqqqqqqqqqwq>[m [1m x mqqqqqq / <qqqqqqqqj x [m [1m tq> [1;4mEDIT[m[1m [1;4mSTRING[m[1m IS <quoted-string> qqqqqqqqqqqqqqqqqqqqqqqqu [m [1m x x [m [1m tq> [1;4mQUERY[m[1m [1;4mNAME[m[1m FOR qwq> DTR qqqqqqqqwq> IS <quoted-string> u [m [1m x mq> DATATRIEVE qj x [m [1m tq> [1;4mDEFAULT[m[1m [1;4mVALUE[m[1m FOR qwq> DTR qqqqqqqqwq> IS <literal> qqqu [m [1m x mq> DATATRIEVE qj x [m [1m tq> [1;4mNO[m[1m [1;4mQUERY[m[1m [1;4mHEADER[m[1m qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mNO[m[1m [1;4mEDIT[m[1m [1;4mSTRING[m[1m qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu [m [1m tq> [1;4mNO[m[1m [1;4mQUERY[m[1m [1;4mNAME[m[1m qqqqwqq> FOR qwq> DTR qqqqqqqqwqqqqqqqqqqu [m [1m tq> [1;4mNO[m[1m [1;4mDEFAULT[m[1m [1;4mVALUE[m[1m qj mq> DATATRIEVE qj x [m [1mmq> [1;4mCOMMENT[m[1m IS qwq> <quoted-string>[m [1mqwqqqqqqqqqqqqqqqqqqqqqj[m [1m [m [1mmqqqqqq[m [1m/[m [1m<qqqqqqqqqqj[m [1m [m [1m [m [1m [m
3 – Arguments
3.1 – char-data-types
A character type. See the Data_Types HELP topic for more information on data types.
3.2 – character-set-name
A valid character set.
3.3 – COLLATING_SEQUENCE
Specifies a collating sequence for the named domain. The OpenVMS National Character Set (NCS) utility provides a set of predefined collating sequences and also lets you define collating sequences of your own. The COLLATING SEQUENCE clause accepts both predefined and user-defined NCS collating sequences. Before you use the COLLATING SEQUENCE clause in a CREATE DOMAIN statement, you must first specify the NCS collating sequence for SQL using the CREATE COLLATING SEQUENCE statement. The sequence- name argument in the COLLATING SEQUENCE clause must be the same as the sequence-name in the CREATE COLLATING SEQUENCE statement.
3.4 – COMMENT_IS
Adds a comment about the domain. SQL displays the text of the comment when it executes a SHOW DOMAIN statement. Enclose the comment in single quotation marks ( ') and separate multiple lines in a comment with a slash mark (/).
3.5 – DATABASE ALIAS alias
In the FROM path-name clause, specifies the name for an attach to a particular database. SQL adds the domain definition to the database referred to by the alias. If you do not specify an alias, SQL adds the domain definition to the default database. See the User_Supplied_Names HELP topic for more information on default databases and aliases.
3.6 – date-time-data-types
A data type that specifies a date, time, or interval. See the Data_Types HELP topic for more information about date-time data types.
3.7 – DEFAULT value-expr
Provides a default value for a domain. You can use any value expression including subqueries, conditional, character, date/time, and numeric expressions as default values. See Value Expressions for more information about value expressions. For more information about NULL, see the NULL_Keyword HELP topic. The value expressions described in Value Expressions include DBKEY and aggregate functions. However, the DEFAULT clause is not a valid location for referencing a DBKEY or an aggregate function. If you attempt to reference either, you receive a compile-time error. If you do not specify a DEFAULT for a column, it inherits the DEFAULT from the domain. If you do not specify a default for either the column or domain, SQL assigns NULL as the default value.
3.8 – domain-constraint
Creates a constraint for the named domain. Specify a domain constraint when you create a domain to limit which values can be stored in columns based on the domain. Domain constraints specify that columns based on the domain contain only certain data values or that data values can or cannot be null. Use the CHECK clause to specify that a value must be within a specified range or that it matches a list of values. When you specify a CHECK clause for a domain constraint, you ensure that all values stored in columns based on the domain are checked consistently.
3.9 – domain-name
The name of a domain you want to create. The domain name must be unique among domain names in the schema. You can qualify it with an alias or (in multischema databases only) a schema name.
3.10 – FROM pathname
Specifies the repository path name of a repository field definition. SQL creates the domain using the definition from this field and gives the domain the name of the field definition. Creating a domain based on a repository domain definition is useful when many applications share the same definition. Changes to the common definition can be automatically reflected in all applications that use it. You can create a domain using the FROM path-name clause only if the field definition in the repository was originally created using the repository CDO utility. For instance, you cannot create a domain using the FROM path-name clause if the definition was created in the repository as part of an SQL session. Oracle Rdb requires that the field names referenced in the VALID IF expression of the CDO utility match the name of the global field being defined or changed. NOTE Changes by other users or applications to the field definition in the repository will affect the domain definition once the database is integrated to match the repository with an INTEGRATE DATABASE . . . ALTER FILES statement. You can use the FROM path-name clause only if the database was attached specifying PATHNAME. You can specify either a full repository path name or a relative repository path name. You cannot specify formatting clauses when you use the FROM path- name form of the CREATE DOMAIN statement. You cannot use the FROM path-name clause when embedding a CREATE DOMAIN statement in a CREATE DATABASE statement.
3.11 – data-type
Syntax options: IS data-type AS data-type A valid SQL data type. See the Data_Types HELP topic for more information on data types.
3.12 – NO_COLLATING_SEQUENCE
Specifies that this domain uses the standard default collating sequence, that is, ASCII. Use the NO COLLATING SEQUENCE clause to override the collating sequence defined for the database in the CREATE DATABASE or ALTER DATABASE statement.
3.13 – sql-and-dtr-clause
Optional SQL and DATATRIEVE formatting clause. See the DATATRIEVE HELP topic for more information on formatting clauses.
3.14 – STORED_NAME_IS
Specifies a name that Oracle Rdb uses to access a domain created in a multischema database. The stored name lets you access multischema definitions using interfaces, such as Oracle RMU, the Oracle Rdb management utility, that do not recognize multiple schemas in one database. You cannot specify a stored name for a domain in a database that does not allow multiple schemas. For more information about stored names, see the User_Supplied_Names HELP topic.
4 – Examples
Example 1: Creating a domain for a standard EMPLOYEE_ID definition The following example creates the domain ID_DOM, which will be a standard definition of columns for the employee ID: SQL> CREATE DOMAIN ID_DOM CHAR(5) SQL> COMMENT IS cont> 'standard definition of employee id'; Example 2: Creating a domain for standard date The following example creates the domain STANDARD_DATE_DOM, which includes the edit string DD-MMM-YYYY: SQL> CREATE DOMAIN STANDARD_DATE_DOM DATE cont> EDIT STRING IS 'DD-MMM-YYYY' SQL> COMMENT IS cont> 'standard definition for complete dates'; Example 3: Creating domains with default values The following example creates two domains: ADDRESS_DATA2_DOM and WORK_STATUS_DOM. The ADDRESS_DATA2_DOM domain has a default value of NULL; the WORK_STATUS_DOM domain has a default value of 1 to signify full-time work status. SQL> CREATE DOMAIN ADDRESS_DATA2_DOM CHAR(20) cont> DEFAULT NULL; SQL> -- SQL> CREATE DOMAIN WORK_STATUS_DOM SMALLINT cont> DEFAULT 1; Example 4: Basing a domain on a repository field definition The following example illustrates using the repository as a source for the definition in a CREATE DOMAIN statement: $ SQL$ SQL> ATTACH 'PATHNAME CDD$TOP.SQL.RDB.TEST.DATE'; SQL> CREATE DOMAIN FROM DOMAIN_TEST; SQL> SHOW DOMAIN User domains in database with pathname SYS$COMMON:[CDDPLUS]SQL.RDB.TEST.DATE;1 DOMAIN_TEST BIGINT Example 5: Creating a domain with a collating sequence The following example creates a domain with the predefined NCS collating sequence SPANISH. Note that you must first execute the CREATE COLLATING SEQUENCE statement: SQL> -- SQL> CREATE COLLATING SEQUENCE SPANISH SPANISH; SQL> CREATE DOMAIN LAST_NAME_SPANISH CHAR(14) cont> COLLATING SEQUENCE IS SPANISH; SQL> -- SQL> SHOW DOMAIN LAST_NAME_SPANISH LAST_NAME_SPANISH CHAR(14) Collating sequence: SPANISH Example 6: Creating a domain using the database default character set For each of the following examples, assume the database was created specifying the database default character set as DEC_ KANJI and the national character set as KANJI. The following example creates the domain DEC_KANJI_DOM using the database default character set: SQL> SHOW CHARACTER SET; Default character set is DEC_KANJI National character set is KANJI Identifier character set is DEC_KANJI Literal character set is DEC_KANJI Alias RDB$DBHANDLE: Identifier character set is DEC_KANJI Default character set is DEC_KANJI National character set is KANJI SQL> CREATE DOMAIN DEC_KANJI_DOM CHAR(8); SQL> SHOW DOMAIN User domains in database with filename MIA_CHAR_SET DEC_KANJI_DOM CHAR(8) Because the CREATE DOMAIN statement does not specify a character set, Oracle Rdb defines the domain using the database default character set. The database default character set does not display with the SHOW DOMAIN statement. An equivalent statement to the previous CREATE DOMAIN statement is: SQL> CREATE DOMAIN DEC_KANJI_DOM CHAR(8) CHARACTER SET DEC_KANJI; Example 7: Creating a domain using the national character set The following example creates the domain KANJI_DOM using the NCHAR data type to designate use of the national character set: SQL> CREATE DOMAIN KANJI_DOM NCHAR(8); SQL> SHOW DOMAIN User domains in database with filename MIA_CHAR_SET DEC_KANJI_DOM CHAR(8) KANJI_DOM CHAR(8) KANJI 8 Characters, 16 Octets When a character set other than the default is specified, the SHOW DOMAIN statement displays the character set associated with the domain. Two statements equivalent to the previous CREATE DOMAIN statement are: SQL> CREATE DOMAIN KANJI_DOM NATIONAL CHAR(8); SQL> CREATE DOMAIN KANJI_DOM CHAR(8) CHARACTER SET KANJI; Example 8: Creating a domain constraint The following example creates a domain constraint: SQL> -- The SET DIALECT 'SQL99' statement sets the default date format SQL> -- to the ANSI/ISO SQL standard format. SQL> -- SQL> SET DIALECT 'SQL99'; SQL> -- SQL> -- The following domain ensures that any dates inserted into the database SQL> -- are later than January 1, 1900: SQL> -- SQL> CREATE DOMAIN TEST_DOM DATE cont> DEFAULT NULL cont> CHECK (VALUE > DATE'1900-01-01' OR cont> VALUE IS NULL) cont> NOT DEFERRABLE; SQL> SQL> -- The following example creates a table with one column based on the SQL> -- domain TEST_DOM: SQL> -- SQL> CREATE TABLE DOMAIN_TEST cont> (DATE_COL TEST_DOM); SQL> -- SQL> -- SQL returns an error if you attempt to insert data that does not SQL> -- conform to the domain constraint: SQL> -- SQL> INSERT INTO DOMAIN_TEST cont> VALUES (DATE'1899-01-01'); %RDB-E-NOT_VALID, validation on field DATE_COL caused operation to fail