Bulk Insert PL/SQL - skip duplicates
623645Mar 28 2008 — edited Mar 28 2008Hello gurus,
I am trying to copy data from table t1 to table t2 skipping any duplicates. Basically I enable constraints on t2 and run this code:
DECLARE
a t1.col1%TYPE;
b t1.col2%TYPE;
c t1.col3%TYPE;
CURSOR c1 IS SELECT col1 from t1;
CURSOR c2 IS SELECT col2 from t1;
CURSOR c3 IS SELECT col3 from t1;
BEGIN
OPEN c1;
OPEN c2;
OPEN c3;
LOOP
FETCH c1 into a;
FETCH c2 into b;
FETCH c3 into c;
EXIT WHEN c1%NOTFOUND;
BEGIN
INSERT INTO t2 VALUES(a,b,c);
COMMIT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
BEGIN
NULL;
END; -- end exception
END;
END LOOP;
END;
This works fine, but very slow on big tables. Is there a way to improve? I am using Oracle 8i.