17,140
社区成员




-- 给你写个例子
SQL>
SQL> create table test(a varchar(10) not null, b varchar(10));
Table created
SQL> begin
2 insert into test values('A',NULL);
3 insert into test values('A',NULL);
4 insert into test values('B','1');
5 insert into test values('B','1');
6 end;
7 /
PL/SQL procedure successfully completed
SQL> alter table test
2 add constraint uk_test unique (a,b) deferrable disable novalidate;
Table altered
SQL> alter table test enable novalidate constraint uk_test;
Table altered
SQL> insert into test values('A',NULL) ;
insert into test values('A',NULL)
ORA-00001: 违反唯一约束条件 (ITSM_USER.UK_TEST)
SQL> commit ;
Commit complete
SQL> insert into test values('C',NULL) ;
1 row inserted
SQL> commit ;
Commit complete
SQL> insert into test values('C',NULL) ;
insert into test values('C',NULL)
ORA-00001: 违反唯一约束条件 (ITSM_USER.UK_TEST)
SQL> commit ;
Commit complete
SQL> select * from test ;
A B
---------- ----------
A
A
B 1
B 1
C
SQL> drop table test purge;
Table dropped
SQL>