国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

Oracle索引也可以這么建

2019-11-09 13:34:31
字體:
供稿:網(wǎng)友

 需求是status為new的id需要唯一,其他的數(shù)據(jù)不做要求。

drop table test purge;

create table test(  id  number,  status varchar2(10));create unique index uind_t_id on test(decode(status,'new',id,null));insert into test values(1,'new'); commit;insert into test values(2,'new'); commit;insert into test values(1,'old'); commit;insert into test values(2,'old'); commit;insert into test values(1,'new'); *第 1 行出現(xiàn)錯誤:

ORA-00001: 違反唯一約束條件 (UIND_T_ID)

insert into test values(2,'old'); commit;

select * from test;    ID STATUS------- ----------      1 new      2 new      1 old

      2 old

      2 old

可能有同學要問為什么status和id建一個聯(lián)合的唯一索引,這種做法達不到要求,實驗一下:

truncate table test;drop index uind_t_id;         create unique index uind_t_id on test(id,status);insert into test values(1,'new'); commit;insert into test values(2,'new'); commit;insert into test values(1,'old'); commit;insert into test values(2,'old'); commit;insert into test values(1,'new')*第 1 行出現(xiàn)錯誤:ORA-00001: 違反唯一約束條件 (SPROC4GD_DEV.UIND_T_ID)insert into test values(2,'old')*第 1 行出現(xiàn)錯誤:ORA-00001: 違反唯一約束條件 (SPROC4GD_DEV.UIND_T_ID)select * from test;        ID STATUS---------- ----------         1 new         2 new         1 old         2 old

可以看到這個不滿足其他的數(shù)據(jù)不做要求的需求。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 纳雍县| 平定县| 当涂县| 嘉黎县| 合作市| 西藏| 双流县| 宁明县| 长宁区| 峨山| 富平县| 基隆市| 观塘区| 台南县| 锡林浩特市| 法库县| 桦南县| 勃利县| 方山县| 河间市| 遵化市| 隆子县| 天等县| 拜城县| 北海市| 清徐县| 仙居县| 多伦县| 毕节市| 连山| 惠安县| 浠水县| 荔波县| 康乐县| 筠连县| 洪雅县| 房产| 洛隆县| 沁源县| 依兰县| 莒南县|