SQL$HELP_OLD72.HLB  —  CREATE  DOMAIN  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
Close Help