【发布时间】:2025-11-22 05:45:02
【问题描述】:
ORA-01427: 单行子查询在更新语句中返回多于一行
嗨。对于以下查询,出现 ORA-01427 错误。
我正在尝试从 country_population 获取生日并将其设置为 city_population 中的 fave_date。不需要其他更简单的方法来执行此操作,我只需要一些建议如何消除错误并让查询工作。 谢谢你:)
DECLARE
CURSOR custCur IS
SELECT name, age, weight, height, birthday FROM country_population;
CNTR number(9) := 0;
BEGIN
FOR curRec IN custCur LOOP
UPDATE city_population srvagr
SET srvagr.date1 = SYSDATE,
srvagr.fave_date =
(select curRec.birthday from country_population curRec
where srvagr.name=curRec.name
and srvagr.age=curRec.age
and srvagr.weight=curRec.weight
and srvagr.height=curRec.height),
srvagr.date2 = SYSDATE,
srvagr.date3 = SYSDATE,
srvagr.status = 'visitor',
srvagr.note = 'Noted'
WHERE
srvagr.name = curRec.name
and srvagr.age = curRec.age
and srvagr.weight = curRec.weight
and srvagr.height = curRec.height
and srvagr.status != 'visitor'
and srvagr.fave_date is null;
CNTR := CNTR + 1;
if CNTR = 1000
then
COMMIT;
CNTR := 0;
end if;
END LOOP;
COMMIT;
【问题讨论】:
-
错误比较明显,子查询返回的条件超过 1 行 - 您需要进一步细化这些条件,或者在多行的情况下做出关于选择什么
标签: sql oracle for-loop update-statement