Add condition constraint with 'and' operator : Check « Table « Oracle PL/SQL Tutorial

Home
Oracle PL/SQL Tutorial
1.Introduction
2.Query Select
3.Set
4.Insert Update Delete
5.Sequences
6.Table
7.Table Joins
8.View
9.Index
10.SQL Data Types
11.Character String Functions
12.Aggregate Functions
13.Date Timestamp Functions
14.Numerical Math Functions
15.Conversion Functions
16.Analytical Functions
17.Miscellaneous Functions
18.Regular Expressions Functions
19.Statistical Functions
20.Linear Regression Functions
21.PL SQL Data Types
22.PL SQL Statements
23.PL SQL Operators
24.PL SQL Programming
25.Cursor
26.Collections
27.Function Procedure Packages
28.Trigger
29.SQL PLUS Session Environment
30.System Tables Data Dictionary
31.System Packages
32.Object Oriented
33.XML
34.Large Objects
35.Transaction
36.User Privilege
Oracle PL/SQL Tutorial » Table » Check 
6.13.5.Add condition constraint with 'and' operator
SQL>
SQL>
SQL> CREATE TABLE product (
  2       product_name     VARCHAR2(25PRIMARY KEY,
  3       product_price    NUMBER(4,2),
  4       quantity_on_hand NUMBER(5,0),
  5       last_stock_date  DATE
  6       );

Table created.

SQL>
SQL> INSERT INTO product VALUES ('Product 1', 99,  1,    '15-JAN-03');

row created.

SQL> INSERT INTO product VALUES ('Product 2', 75,  1000'15-JAN-02');

row created.

SQL> INSERT INTO product VALUES ('Product 3', 50,  100,  '15-JAN-03');

row created.

SQL> INSERT INTO product VALUES ('Product 4', 25,  10000null);

row created.

SQL> INSERT INTO product VALUES ('Product 5', 9.95,1234'15-JAN-04');

row created.

SQL> INSERT INTO product VALUES ('Product 6', 45,  1,    TO_DATE('December 31200811:30 P.M.','Month dd, YYYY, HH:MI P.M.'));

row created.

SQL>
SQL>
SQL>
SQL> ALTER TABLE product ADD CONSTRAINT positive_quantity CHECK(
  2       quantity_on_hand IS NOT NULL
  3       AND
  4       quantity_on_hand >=0
  5       );

Table altered.

SQL>
SQL> drop table product;

Table dropped.

SQL>
SQL>
6.13.Check
6.13.1.Create a table with check constraint
6.13.2.Adding a CHECK Constraint
6.13.3.Use comparison operators with a CHECK constraint
6.13.4.Constraint with Two conditions
6.13.5.Add condition constraint with 'and' operator
6.13.6.Check constraint with decode and nvl2
6.13.7.Check constraint with MOD function
6.13.8.A column with upper case constraint
6.13.9.check constraint: must be positive value
6.13.10.Check constraint: one column must less than another column
6.13.11.Add constraint to ensure that value from one column is bigger than that from another
6.13.12.Salary column value cannot be greater than 1000
6.13.13.Setting CHECK constraint for number type field
6.13.14.Setting the Regular expression check for varchar field
6.13.15.Use char function to build default column value
6.13.16.Use decode() function in check constraints
6.13.17.Violate a ckeck constraint
6.13.18.Must be upper case
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.