我使用Oracle 11g 我有一张桌子:
create table test (one number(2), two number(2));
有两行:
insert into test (one, two) values (1, 1);
insert into test (one, two) values (2, null);
commit;
现在我创建一个例外表:
create table exceptions(row_id rowid,
owner varchar2(30),
table_name varchar2(30),
constraint varchar2(30));
现在我想创建test的主键:
alter table test add constraint test_pk primary key (one, two) exceptions into exceptions;
当然我收到以下错误:ORA-01449
但导致异常的行不在异常表中?
任何人都可以帮助我。提前致谢
沃尔夫冈
答案 0 :(得分:8)
为此,您必须首先创建禁用的约束:
ALTER TABLE test ADD CONSTRAINT test_pk PRIMARY KEY (one, two) DISABLE;
然后,启用带例外的约束:
ALTER TABLE TEST ENABLE CONSTRAINT test_pk EXCEPTIONS INTO exceptions;
然后您可以选择结果:
SQL> SELECT * FROM EXCEPTIONS;
ROW_ID OWNER TABLE_NAME CONSTRAINT
------------------ ----- ---------- ----------
AAHpV4AAHAAApliAAB XXX TEST TEST_PK