SQL> SQL> create table test(id int, createtime date); Table created SQL> alter table test add constraint ck_cdate 2 check(createtime between date'1990-01-01' and date'2015-12-31'); Table altered SQL> -- 成功 SQL> insert into test values(1, date'1995-02-05'); 1 row inserted SQL> insert into test values(2, date'2014-02-05'); 1 row inserted SQL> -- 下面两条失败 SQL> insert into test values(3, date'2025-02-05'); insert into test values(3, date'2025-02-05') ORA-02290: 违反检查约束条件 (ORACLE.CK_CDATE) SQL> insert into test values(4, date'1900-02-05'); insert into test values(4, date'1900-02-05') ORA-02290: 违反检查约束条件 (ORACLE.CK_CDATE) SQL> select * from test; ID CREATETIME --------------------------------------- ----------- 1 1995/2/5 2 2014/2/5 SQL> drop table test purge; Table droppedSQL>
alter table test add constraint ck_cdate check(createtime between date'1990-01-01' and date'2015-12-31');
SQL>
SQL> create table test(id int, createtime date);
Table created
SQL> alter table test add constraint ck_cdate
2 check(createtime between date'1990-01-01' and date'2015-12-31');
Table altered
SQL> -- 成功
SQL> insert into test values(1, date'1995-02-05');
1 row inserted
SQL> insert into test values(2, date'2014-02-05');
1 row inserted
SQL> -- 下面两条失败
SQL> insert into test values(3, date'2025-02-05');
insert into test values(3, date'2025-02-05')
ORA-02290: 违反检查约束条件 (ORACLE.CK_CDATE)
SQL> insert into test values(4, date'1900-02-05');
insert into test values(4, date'1900-02-05')
ORA-02290: 违反检查约束条件 (ORACLE.CK_CDATE)
SQL> select * from test;
ID CREATETIME
--------------------------------------- -----------
1 1995/2/5
2 2014/2/5
SQL> drop table test purge;
Table droppedSQL>
check(createtime between date'1990-01-01' and date'2015-12-31');