国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 勐海县| 中阳县| 广东省| 革吉县| 江安县| 南京市| 翁源县| 松滋市| 满洲里市| 龙海市| 江达县| 清丰县| 永仁县| 松溪县| 宾阳县| 泰顺县| 和政县| 高雄县| 宣汉县| 南靖县| 梅河口市| 宝丰县| 嘉鱼县| 甘肃省| 长兴县| 嫩江县| 富蕴县| 广南县| 鸡东县| 巴林右旗| 老河口市| 临城县| 嘉荫县| 吉木乃县| 思茅市| 襄垣县| 福泉市| 天峨县| 安庆市| 满城县| 仙居县|