1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| SQL> drop table t
2 /
Table dropped.
SQL> create table t (c1 number, c2 number, c3 number, c4 number)
2 /
Table created.
SQL>
SQL> create unique index idx1_t on t (
2 case when c1 = 1 then c1 end,
3 case when c1 = 1 then c2 end,
4 case when c1 = 1 then c3 end)
5 /
Index created.
SQL> create unique index idx2_t on t (
2 case when c1 not in (1, 2) then c1 end,
3 case when c1 not in (1, 2) then c2 end)
4 /
Index created.
SQL> insert into t select 1,2,3,4 from dual;
1 row created.
SQL> insert into t select 1,2,3,4 from dual;
insert into t select 1,2,3,4 from dual
*
ERROR at line 1:
ORA-00001: unique constraint (SKUATAMAD.IDX1_T) violated
SQL> insert into t select 1,3,3,4 from dual;
1 row created.
SQL> insert into t select 2,2,2,2 from dual;
1 row created.
SQL> insert into t select 2,2,2,2 from dual;
1 row created.
SQL> insert into t select 3,2,2,2 from dual;
1 row created.
SQL> insert into t select 3,2,2,2 from dual;
insert into t select 3,2,2,2 from dual
*
ERROR at line 1:
ORA-00001: unique constraint (SKUATAMAD.IDX2_T) violated
SQL> insert into t select 3,3,2,2 from dual;
1 row created.
SQL> select * from t;
C1 C2 C3 C4
---------- ---------- ---------- ----------
1 2 3 4
1 3 3 4
2 2 2 2
2 2 2 2
3 2 2 2
3 3 2 2
6 rows selected.
SQL> |
Partager