问题描述:将数据从中间表往业务表插入时,提示唯一键重复
1 Insert into table1 (code)(select distinct code from table2)
上面的数据执行提示错误,我们选中后半部分查询,发现数据正常,code是唯一的
1 Create table table3 as select distinct code from table2;
2 Insert into table1(code)(select code from table3)
这种方式能正常执行
1 Insert into table1 (code) (select code from table3 group by code)
这种方式也能正常执行,继续测试下面的语句也能正常执行
1 Insert into table1 (code)(select * from (select distinct code from table2))
切换数据版本测试发现第一条语句也能正常执行。
结论: oracle 10.2.0.1.0版本无法识别的这种写法导致distinct失效
解决办法: 在select的外面再套上一层查询即可