|
younghuijun 发表于 2015-2-16 09:38 ![]()
AskTom这篇文章可能对你有用:
https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID: ...
tom的办法,出错的时候,exceptions表自动被填充?
how about adding a unique constraint on the columns in question and using "exceptions
into". For example:
ops$tkyte@ORA817DEV.US.ORACLE.COM> create table t ( a int, b int, c int );
Table created.
ops$tkyte@ORA817DEV.US.ORACLE.COM> exec gen_data( 'T', 500 );
PL/SQL procedure successfully completed.
ops$tkyte@ORA817DEV.US.ORACLE.COM> insert into t select * from t where rownum < 10;
9 rows created.
ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> create table exceptions(row_id rowid,
2 owner varchar2(30),
3 table_name varchar2(30),
4 constraint varchar2(30));
Table created.
ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> alter table t add constraint t_unique unique(a,b,c)
exceptions into exceptions;
alter table t add constraint t_unique unique(a,b,c) exceptions into exceptions
*
ERROR at line 1:
ORA-02299: cannot validate (OPS$TKYTE.T_UNIQUE) - duplicate keys found
ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> create table dups
2 as
3 select *
4 from t
5 where rowid in ( select row_id from exceptions )
6 /
create table dups
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
ops$tkyte@ORA817DEV.US.ORACLE.COM> delete from t where rowid in ( select row_id from
exceptions );
18 rows deleted.
ops$tkyte@ORA817DEV.US.ORACLE.COM> insert into t select distinct * from dups;
9 rows created.
|
|