BC remote Oracle DBA - Call (800) 766-1884  
Oracle Consulting Oracle Training Development

Remote DBA

Remote DBA Plans  

Remote DBA Service

Remote DBA RAC

   
Remote DBA Oracle Home
Remote DBA Oracle Training
Remote DBA SQL Tuning Consulting
Remote DBA Oracle Tuning Consulting
Remote DBA Data Warehouse Consulting
Remote DBA Oracle Project Management
Remote DBA Oracle Security Assessment
Remote DBA Unix Consulting
Burleson Books
Burleson Articles
Burleson Web Courses
Burleson Qualifications
Oracle Links
Remote DBA Oracle Monitoring
Remote DBA Support Benefits
Remote DBA Plans & Prices
Our Automation Strategy
What We Monitor
Oracle Apps Support
Print Our Brochure
Contact Us (e-mail)
Oracle Job Opportunities
Oracle Consulting Prices





   

 

 

 

Remote DBA services

Remote DBA Support

Remote DBA RAC

Remote DBA Reasons

Remote Oracle Tuning

Remote DBA Links

Oracle DBA Support

Oracle DBA Forum

Oracle Disaster

Oracle Training

Oracle Tuning

Oracle Training

 Remote DBA SQL Server

Remote MSSQL Consulting

Oracle DBA Hosting

Oracle License Negotiation

 

 


 

 

 

 

 
 

EnterpriseDB: Domains

Oracle Tips by Burleson Consulting
 

A domain is a data type that has constraints applied to it.

CREATE DOMAIN

CREATE DOMAIN name AS data_type
            [ DEFAULT <default> ]
            [ CONSTRAINT {NOT NULL|NULL|CHECK (<expression>)}]

A domain can be a data item such as sex.  The definition of sex might be CHAR(1) and it may be constrained to values  of 'M', 'F', or 'U' (for unknown).  We can set a default of 'U' and force it to not accept NULL values.  To create this domain, we would use:

CREATE DOMAIN sex AS CHAR
  CONSTRAINT sex_cons
  DEFAULT 'U'
  NOT NULL
  CHECK (VALUE IN ('M', 'F', 'U'));

Default, check and NULL/NOT NULL are optional and the domain will default to nullable.  The CONSTRAINT name is required if you are defining a DEFAULT, NULL/NOT NULL or CHECK.

You must use the keyword VALUE when you reference the column instead of using the actual column name. VALUE is the equivalent of SELF in OO programming.

You can include a SCHEMA name in your declaration if you want the domain created in a particular schema.

CREATE DOMAIN hr.emp_ssn AS VARCHAR2(9)
  CONSTRAINT hr_emp_ssn
  CHECK( LENGTH(VALUE)  =  9);

You can then use your domains in your create table commands:

CREATE TABLE emp_stuff (
  empno NUMBER(5),
  employee_sex sex;
  employee_ssn hr.emp_ssn );

ALTER DOMAIN

You can alter a domain to change a default or a NULL/NOT NULL.

ALTER DOMAIN sex SET DEFAULT 'M';
ALTER DOMAIN sex SET NULL;

You can also drop the default and the NULL/NOT NULL.

ALTER DOMAIN sex DROP DEFAULT;
ALTER DOMAIN sex DROP NOT NULL;

You can add a new constraint:

ALTER DOMAIN sex ADD
  CONSTRAINT upper_sex_cons
    CHECK (UPPER(VALUE) = VALUE);

Or drop a constraint.

ALTER DOMAIN sex DROP CONSTRAINT upper_sex_cons;

You can change the schema where it resides.

ALTER DOMAIN sex SET SCHEMA hr;

GRANT DOMAIN

You don't need any special grants for a domain.

REVOKE DOMAIN

There is nothing to revoke from a domain.

DROP DOMAIN

You can drop a domain with the DROP DOMAIN command.

DROP DOMAIN sex;

If the DOMAIN is being used anywhere in the database, you must use the CASCADE option to also remove the domain from those objects.

DROP DOMAIN sex CASCADE;




This is an excerpt from the book "EnterpriseDB: The Definitive Reference" by Rampant TechPress.


Expert Remote DBA

BC is America's oldest and largest Remote DBA Oracle support provider.  Get real Remote DBA experts, call
BC Remote DBA today.

 

 

Remote DBA Service
 

Oracle Tuning Book

 

Advance SQL Tuning Book 

BC Oracle support

Oracle books by Rampant

Oracle monitoring software

 

 

 

 

 

 

BC Remote Oracle Support

Remote DBA

Remote DBA Services

Copyright © 1996 -  2013 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.



Hit Counter