OraOLEDB:ORA-01427:单行子查询返回多行

时间:2014-03-14 18:43:09

标签: sql oracle

在我的数据块中运行此子查询时收到SQL错误

我试图将员工以前的职位退还给他们的最后一个雇主

这是我的问题:

(select
(case
WHEN

(select
distinct
'x'
from aprehis a
where
donor.pidm = a.aprehis_pidm
and a.aprehis_empr_pidm is null
and trunc(a.aprehis_to_date) =

(select max(trunc(aprehis_to_date))
from aprehis b
where b.aprehis_pidm = donor.pidm
and trunc (b.aprehis_to_date) is not null))= 'x'
THEN
(select distinct (aprehis_empl_position)
from aprehis where
aprehis_pidm = donor.pidm
and aprehis_empr_name =

(select max(aprehis_empr_name)
from aprehis d
where d.aprehis_pidm = donor.pidm
and trunc(d.aprehis_to_date) =

(select max(trunc(aprehis_to_date))
from aprehis c
where c.aprehis_pidm = donor.pidm
and trunc (c.aprehis_to_date) is not null)))

ELSE

 (select distinct (aprehis_empl_position)
 from aprehis where aprehis_pidm = donor.pidm
 and aprehis_empr_name =
 (select spriden_last_name
 from spriden
  where spriden_change_ind is null
  and spriden_pidm =

 (select max(aprehis_empr_pidm) from aprehis e
  where e.aprehis_pidm = donor.pidm
  and e.aprehis_empr_pidm is not null
   and trunc(e.aprehis_to_date)=(select max(trunc(aprehis_to_date))
  from aprehis b

非常感谢任何帮助。

非常感谢

1 个答案:

答案 0 :(得分:0)

请尝试在两个不同的地方更改以下行:     选择distinct(aprehis_empl_position)

于:     选择MAX(aprehis_empl_position)