We had another solution: Use Oracle's internal EXCEPTIONS table to handle this.<br><br><u>Step 1</u>: Cate your own exceptions table, say mb_exceptions:<br><FONT FACE=monospace><br>drop table mb_exceptions;<br>create table mb_exceptions(<br> row_id rowid,<br> owner varchar2(30),<br> table_name varchar2(30),<br> constraint varchar2(30));<br></font><br>(This is taken from script $ORACLE_HOME/rdbms/admin/utlexcpt.sql)<br><br><u>Step 2</u>: Create your source table:<br><FONT FACE=monospace><br>create table t2 (c2 number);<br><br>insert into t2 values (1);<br>insert into t2 values (2);<br>insert into t2 values (100);<br>commit;<br></font><br><br><u>Step 3</u>: Create your destination table:<br><FONT FACE=monospace><br>create table t1 (c1 number);<br></font><br><br><u>Step 4</u>: Insert from source to destination<br>(NOTE: Make sure to disable the constraints (if any) that would cause the violation. None here yet.)<br><br><FONT FACE=monospace><br>insert into t1 select * from t2;<br></font><br>Nothing bad yet.<br><br><u>Step 5</u>: Now, enable the constraint to check the violation. Here assume the constraint is column C1 must be <10.<br><FONT FACE=monospace><br>alter table t1 add constraints ck_t1 check (c1 <10)<br> exceptions into mb_exceptions;<br></font><br><br>When enabling this constraints, Oracle creates a record in the exception table for every record in T1 which fails the constraint. Note that it does not move the bad records out of T1 and the constraints still not enabled yet.<br><br><u>Step 6</u>: All your bad records are now in table mb_exceptions. Just display it:<br><FONT FACE=monospace><br>prompt Table t1:<br>select rowid, c1 from t1;<br><br>prompt Table mb_exceptions:<br>select * from mb_exceptions;<br></font><br><br>Their results are:<br><FONT FACE=monospace><br>Table t1:<br>ROWID C1<br>------------------ ----------<br>AAQVUAACUAAAPYbAAA 1<br>AAQVUAACUAAAPYbAAB 2<br><font color=red>AAQVUAACUAAAPYbAAC</font> 100<br></font><br><br>Table mb_exceptions: <br><FONT FACE=monospace><br>ROW_ID OWNER TABLE_NAME CONSTRAINT<br>------------------ ------- ------------ ------------<br><font color=red>AAQVUAACUAAAPYbAAC</font> MDBUI T1 CK_T1<br></font><br><br>Here you see the rowid of the bad record. You can now issue a delete statement based on this rowid to delete this offending record. Or you may want to save it in some other tables for further analysis, such as display these bad records:<br><FONT FACE=monospace><br>select t1.*<br>from t1, mb_exceptions e<br>where e.row_id = t1.rowid;<br></font><br>Its results are:<br><FONT FACE=monospace><br> C1<br>----------<br> 100<br></font><br>