gpt4 book ai didi

plsql - 使用 PLSQL 时,此 SELECT 语句中需要 INTO 子句

转载 作者:行者123 更新时间:2023-12-01 17:18:23 26 4
gpt4 key购买 nike

我收到以下错误。在 SELECT CASE 语句处收到错误。

PLS-00428: an INTO clause is expected in this SELECT statement

FOR REMS IN cur_names LOOP

SELECT CASE
WHEN EXISTS (SELECT 1
FROM SupplyTable
WHERE FirstName = REMS.Names)
THEN 'Y'
ELSE 'N'
END AS rec_exists
FROM dual;

IF rec_exists = 'Y' THEN
FName := REMS.Names;
ELSE
FName := 'Gen';
END IF;
END LOOP;

最佳答案

您不能在 pl sql 代码中进行随机选择。它必须位于带有 into 子句的循环、游标中。只需在此处包含一个 into 子句即可。

declare 
v_value varchar2(1);
begin
...
FOR REMS IN cur_names LOOP

SELECT CASE
WHEN EXISTS (SELECT 1
FROM SupplyTable
WHERE FirstName = REMS.Names)
THEN 'Y'
ELSE 'N'
END AS rec_exists
INTO v_value
FROM dual;
IF v_value = 'Y' THEN
FName := REMS.Names;
ELSE
FName := 'Gen';
END IF;
END LOOP;
...

或循环

FOR REMS IN cur_names LOOP

for i in
(
SELECT CASE
WHEN EXISTS (SELECT 1
FROM SupplyTable
WHERE FirstName = REMS.Names)
THEN 'Y'
ELSE 'N'
END AS rec_exists
FROM dual
)
loop
IF i.rec_exists = 'Y' THEN
FName := REMS.Names;
ELSE
FName := 'Gen';
END IF;
end loop;
END LOOP;

关于plsql - 使用 PLSQL 时,此 SELECT 语句中需要 INTO 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37567293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com