📅  最后修改于: 2020-11-16 01:15:18             🧑  作者: Mango
在Oracle中,检查约束对表的每一行都有特定的条件。
CREATE TABLE table_name
(
column1 datatype null/not null,
column2 datatype null/not null,
?
CONSTRAINT constraint_name CHECK (column_name condition) [DISABLE]
);
CREATE TABLE student (id numeric(4), name varchar2(50), CONSTRAINT check_id CHECK(id BETWEEN 1 and 10))
注意:在创建表的过程中,我们应用了一个约束,其中只能插入1至10行。因此,在下面的查询中插入了12个字段。如果将生成错误消息。
INSERT ALL
INTO student(id, name) VALUES (1, 'shristee')
INTO student(id, name) VALUES (2, 'heena')
INTO student(id, name) VALUES (3, 'mohit')
INTO student(id, name) VALUES (4, 'shashank')
INTO student(id, name) VALUES (5, 'avinash')
INTO student(id, name) VALUES (6, 'shweta')
INTO student(id, name) VALUES (7, 'suman')
INTO student(id, name) VALUES (8, 'rohan')
INTO student(id, name) VALUES (9, 'ali')
INTO student(id, name) VALUES (10, 'dolly')
INTO student(id, name) VALUES (11,?mona?)
INTO student(id, name) VALUES (12, 'kiran')
SELECT * FROM dual;
INSERT ALL
INTO student(id, name) VALUES (1, 'shristee')
INTO student(id, name) VALUES (2, 'heena')
INTO student(id, name) VALUES (3, 'mohit')
INTO student(id, name) VALUES (4, 'shashank')
INTO student(id, name) VALUES (5, 'avinash')
INTO student(id, name) VALUES (6, 'shweta')
INTO student(id, name) VALUES (7, 'suman')
INTO student(id, name) VALUES (8, 'rohan')
INTO student(id, name) VALUES (9, 'ali')
INTO student(id, name) VALUES (10, 'dolly')
SELECT * FROM dual;