PLS-00428:此 SELECT 语句中需要 INTO 子句

PLS-00428: an INTO clause is expected in this SELECT statement(PLS-00428:此 SELECT 语句中需要 INTO 子句)

本文介绍了PLS-00428:此 SELECT 语句中需要 INTO 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am wanting to store a Rownum as a variable rather than use a costly Join. I need to get this from a Select statement as the Rownum will be different on various environments so it cannot be a literal string in the code.

对于上下文,此查询在 Oracle Siebel CRM 模式上执行,并检索特定类型和属性的一些产品.

For context, this query is executed on Oracle Siebel CRM schema and it retrieves some products of specific type and attributes.

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

I tried using the following SQL code in Toad and Oracle SQL Developer, however I am getting the following error:

PLS-00428:此 SELECT 语句中需要 INTO 子句

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 块中,select 语句的列必须赋值给变量,而在 SQL 语句中则不然.

In PLSQL block, columns of select statements must be assigned to variables, which is not the case in SQL statements.

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

The second BEGIN's SQL statement doesn't have INTO clause and that caused the error.

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#LNPLS00601http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/selectinto_statement.htm#CJAJAAIGhttp://pls-00428.ora-code.com/

这篇关于PLS-00428:此 SELECT 语句中需要 INTO 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PLS-00428:此 SELECT 语句中需要 INTO 子句

基础教程推荐