区别于ORACLE SQL不起作用

时间:2015-02-20 05:44:36

标签: sql oracle distinct

我正在尝试从PS_Z_EXS251AE_EMP表中获取不同的emplid字段的数据,并将其与许多空值一起插入PS_Z_EXS253AE_EMP。但是当我运行下面的内容时,它会给我一个错误,说'缺少表情'。如果我删除关键字'distinct',它会运行(但会插入重复的emplids)。有人请帮助我只插入独特的emplids ...

insert into PS_Z_EXS253AE_SSO 
(Z_RESERVED41, Z_SSN, Z_RESERVED38, Z_REC_TYPE_ID, Z_RESERVED11, Z_IDP_NAME_ID, Z_OPERATION_CODE, Z_RESERVED40)
select ' ', ' ', ' ', ' ', ' ', distinct(z_emplid_exs), ' ', ' ' 
from ps_z_exs251ae_emp
where asofdate in( to_date('2015/01/06','yyyy/mm/dd'), to_date('2015/01/05','yyyy/mm/dd') );

1 个答案:

答案 0 :(得分:3)

区别在于整行,而不仅仅是一列。试试这个

insert into PS_Z_EXS253AE_SSO 
(Z_RESERVED41, Z_SSN, Z_RESERVED38, Z_REC_TYPE_ID, Z_RESERVED11, Z_IDP_NAME_ID, Z_OPERATION_CODE, Z_RESERVED40)
select distinct ' ', ' ', ' ', ' ', ' ', z_emplid_exs, ' ', ' ' 
from ps_z_exs251ae_emp
where asofdate in( to_date('2015/01/06','yyyy/mm/dd'), to_date('2015/01/05','yyyy/mm/dd') );