假如現在我有個createtime的列,我想讓時間在1990-1-1至2099-1-1的資料可以匯入。在這個時間范圍外的資料無法匯入,可以實作嗎(可能是個很菜鳥的問題
)
uj5u.com熱心網友回復:
考慮使用 check 嗎 ?uj5u.com熱心網友回復:
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 dropped
SQL>
uj5u.com熱心網友回復:
alter table test add constraint ck_cdatecheck(createtime between date'1990-01-01' and date'2015-12-31');
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/96316.html
標籤:基礎和管理
上一篇:bom表問題
