7

我使用 Oracle 11g。
我有一张桌子:

create table test (one number(2), two number(2));

有 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));

现在我想为测试创建主键:

alter table test add constraint test_pk primary key (one, two) exceptions into exceptions;

当然我得到以下错误:ORA-01449

但是导致异常的行不在异常表中?

有谁能够帮助我。提前致谢

沃尔夫冈

4

1 回答 1

9

为此,您必须首先创建禁用的约束:

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
于 2012-06-26T17:18:07.043 回答