我有以下查询
select distinct name from table1
intersect
select distinct name from table2;
我将结果集加载到 PL/SQL 过程中的游标中,如下所示:
cursor c1 is (select distinct name from table1
intersect
select distinct name from table2);
由于某种原因,结果集中的最后一个值在游标中重复。单独运行查询时不会发生这种情况。任何想法为什么会发生这种情况?
循环代码:
var table.col%type;
BEGIN
OPEN c1;
LOOP
BEGIN
exit when c1%NOTFOUND;
FETCH c1 into var;
INSERT INTO table values (col1, var);
commit;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
CONTINUE;
END;
END LOOP;
END;