【问题标题】:Distinct not working in ORACLE SQL不同的在 ORACLE SQL 中不起作用
【发布时间】:2015-02-20 14:05:01
【问题描述】:

我正在尝试从 PS_Z_EXS251AE_EMP 表中获取不同 emplid 字段的数据,并将其与一些空值一起插入到 PS_Z_EXS253AE_EMP 中。但是当我运行下面它给我一个错误说'缺少表达式'。如果我删除关键字“distinct”,它会运行(但会插入重复的 emplid)。有人可以帮我只插入唯一的 emplid...

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') );

【问题讨论】:

  • distinctNOT 一个函数。请阅读说明书

标签: sql oracle distinct


【解决方案1】:

Distinct 适用于整行,而不仅仅是一列。试试这个

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') );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-04
    • 2021-04-20
    • 1970-01-01
    • 2015-12-31
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    相关资源
    最近更新 更多