oracle 10.2.0.1.0版本及以下版本下insert into select distinct BUG

前几天同事抛过来两个语句,直观上执行结果应该是一样的,但事实确相反,第二条语句的distinct失效了

insert into SWO_UNIT_CONVERT (PRE_UNIT,CUR_UNIT,CONVERT_RATE,INPUT_ER,EMS_NO,IMG_NO)
 SELECT * FROM 
( SELECT DISTINCT UNIT,'CUR-PCS',1,'JRX',EMS_NO,IMG_NO FROM  SWO_BASE_IMG where ems_no='E23265000016' and dcr_times=11)
insert into SWO_UNIT_CONVERT (PRE_UNIT,CUR_UNIT,CONVERT_RATE,INPUT_ER,EMS_NO,IMG_NO)
SELECT DISTINCT UNIT,'CUR-PCS',1,'JRX',EMS_NO,IMG_NO FROM  SWO_BASE_IMG where ems_no='E23265000016' and dcr_times=11

为了简化语句生成如下临时表

create table test1 
(
    note varchar2(50)
)
create table test2
(
    note varchar2(50)
)
insert into test2 values ('222');
insert into test2 values ('222');
commit;
insert into test1(note)
select distinct note from test2;

 

distinct起效,再观察原表的表结构,怀疑表上有默认的guid导致

重建test1

create table test1 
(
    oid VARCHAR2(36) default sys_guid() ,
    note varchar2(50)
)

再次插入

insert into test1(note)
select distinct note from test2;

distinct再次失效

此时发现测试环境在的版本是oracle 10.2.0.1.0,

再找了个测试环境的版本是oracle 10.2.0.4.0,distinct起效

接着再找了个测试环境的版本是oracle 11.2.0.1.0,distinct起效

接着再找了个测试环境的版本是oracle 9.2.0.8.0,distinct失效

 

由此大概可以判断在oracle 10.2.0.1.0及以下版本中以上语句的写法存在问题,必要时在外面再套一层。

posted @ 2017-01-18 16:47  xuzhong86  阅读(383)  评论(0编辑  收藏  举报