我正在尝试为需要根据某些参数更新某些记录的表编写查询。我有几个嵌套选择和几个嵌套子字符串,我想这是让我难以排除故障的原因。我解决了其中的几个ORA-01427:单行子查询已经返回多行问题,但我似乎找不到这个问题。基本上,该脚本所做的是从一条记录中获取两列,并根据多个不同标准根据包含在不同表中的另一条记录更新它们。以下是我正在使用的当前代码:
UPDATE CMC_SBEL_ELIG_ENT p
SET (p.CSPI_ID, p.SBEL_EFF_DT) =
(SELECT co.new_plan, co.ch_dt
FROM sbsb_plan_conv co, cmc_sbel_elig_ent p
WHERE co.ch_dt > p.sbel_eff_dt
and co.ch_dt < current_date
AND co.new_plan <> p.CSPI_ID
AND co.sbsb_ck = p.sbsb_ck
AND p.cspi_id IN co.OLD_PLAN
and p.SBEL_ELIG_TYPE IN ('tm','ce','TM','CE')
)
WHERE (p.cspd_cat IN (
select unique substr(o.old_plan, 1, 1)
from facets_ws.sbsb_plan_conv o
where
substr(o.old_plan, 1, 1) IN (
select substr(y.new_plan, 1, 1)
from sbsb_plan_conv y, cmc_sbel_elig_ent u
where y.sbsb_ck = u.sbsb_ck
AND (p.SBEL_ELIG_TYPE IN ('tm','ce','TM','CE'))
and ((substr(y.new_plan, 1, 1) = 'M'
and substr(y.new_plan, 1, 1) != 'R'
and substr(y.new_plan, 1, 1) != 'D')
or (substr(y.new_plan, 1, 1) = 'R'
and substr(y.new_plan, 1, 1) != 'M'
and substr(y.new_plan, 1, 1) != 'D')
or (substr(y.new_plan, 1, 1) = 'D'
and substr(y.new_plan, 1, 1) != 'R'
and substr(y.new_plan, 1, 1) != 'M'))
and o.sbsb_ck = p.sbsb_ck)
)
);
现在,当我对两个 select 语句运行单个查询时,它们都返回明确的唯一值。所以我相当肯定他们不是问题。