gpt4 book ai didi

sql - PLS-00428:此SELECT语句中应有一个INTO子句

转载 作者:行者123 更新时间:2023-12-03 10:27:22 25 4
gpt4 key购买 nike

我想将Rownum存储为变量,而不是使用昂贵的Join。
我需要从Select语句中获取此信息,因为Rownum在各种环境下都会有所不同,因此它不能是代码中的文字字符串。

对于上下文,此查询在Oracle Siebel CRM架构上执行,并检索某些具有特定类型和属性的产品。

我尝试在Toad和Oracle SQL Developer中使用以下SQL代码,但是出现以下错误:

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



这是代码
    DECLARE
PROD_ROW_ID varchar(10) := NULL;
BEGIN
SELECT ROW_ID INTO VIS_ROW_ID FROM SIEBEL.S_PROD_INT WHERE PART_NUM = 'S0146404';

BEGIN
SELECT rtrim(VIS.SERIAL_NUM) || ',' || rtrim(PLANID.DESC_TEXT) || ',' ||
CASE
WHEN PLANID.HIGH = 'TEST123'
THEN
CASE
WHEN to_date(PROD.START_DATE) + 30 > sysdate
THEN 'Y'
ELSE 'N'
END
ELSE 'N'
END
|| ',' || 'GB' || ',' ||
rtrim(to_char(PROD.START_DATE, 'YYYY-MM-DD'))
FROM SIEBEL.S_LST_OF_VAL PLANID
INNER JOIN SIEBEL.S_PROD_INT PROD
ON PROD.PART_NUM = PLANID.VAL
INNER JOIN SIEBEL.S_ASSET NETFLIX
ON PROD.PROD_ID = PROD.ROW_ID
INNER JOIN SIEBEL.S_ASSET VIS
ON VIS.PROM_INTEG_ID = PROD.PROM_INTEG_ID
INNER JOIN SIEBEL.S_PROD_INT VISPROD
ON VIS.PROD_ID = VISPROD.ROW_ID
WHERE PLANID.TYPE = 'Test Plan'
AND PLANID.ACTIVE_FLG = 'Y'
AND VISPROD.PART_NUM = VIS_ROW_ID
AND PROD.STATUS_CD = 'Active'
AND VIS.SERIAL_NUM IS NOT NULL;
END;
END;
/

最佳答案

在PLSQL块中,必须将选择语句的列分配给变量,在SQL语句中不是这种情况。

第二个BEGIN的SQL语句没有INTO子句,这导致了错误。

DECLARE
PROD_ROW_ID VARCHAR (10) := NULL;
VIS_ROW_ID NUMBER;
DSC VARCHAR (512);
BEGIN
SELECT ROW_ID
INTO VIS_ROW_ID
FROM SIEBEL.S_PROD_INT
WHERE PART_NUM = 'S0146404';

BEGIN
SELECT RTRIM (VIS.SERIAL_NUM)
|| ','
|| RTRIM (PLANID.DESC_TEXT)
|| ','
|| CASE
WHEN PLANID.HIGH = 'TEST123'
THEN
CASE
WHEN TO_DATE (PROD.START_DATE) + 30 > SYSDATE
THEN
'Y'
ELSE
'N'
END
ELSE
'N'
END
|| ','
|| 'GB'
|| ','
|| RTRIM (TO_CHAR (PROD.START_DATE, 'YYYY-MM-DD'))
INTO DSC
FROM SIEBEL.S_LST_OF_VAL PLANID
INNER JOIN SIEBEL.S_PROD_INT PROD
ON PROD.PART_NUM = PLANID.VAL
INNER JOIN SIEBEL.S_ASSET NETFLIX
ON PROD.PROD_ID = PROD.ROW_ID
INNER JOIN SIEBEL.S_ASSET VIS
ON VIS.PROM_INTEG_ID = PROD.PROM_INTEG_ID
INNER JOIN SIEBEL.S_PROD_INT VISPROD
ON VIS.PROD_ID = VISPROD.ROW_ID
WHERE PLANID.TYPE = 'Test Plan'
AND PLANID.ACTIVE_FLG = 'Y'
AND VISPROD.PART_NUM = VIS_ROW_ID
AND PROD.STATUS_CD = 'Active'
AND VIS.SERIAL_NUM IS NOT NULL;
END;
END;
/

引用

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/static.htm#LNPLS00601
http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/selectinto_statement.htm#CJAJAAIG
http://pls-00428.ora-code.com/

关于sql - PLS-00428:此SELECT语句中应有一个INTO子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25486543/

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