0

你能告诉我这段代码有什么问题吗?它得到错误编译错误

错误:

PL/SQL: ORA-00933: SQL 命令未正确结束

文本:

IF iCnt > 0 THEN


  WITH S600 AS (


Prod_KEY    NUMBER; 
iCount      NUMBER;                                             

BEGIN
  WITH TEMP_All AS
            (SELECT * FROM TEMP1
             UNION ALL
             SELECT * FROM TEMP2
             UNION ALL
             SELECT * FROM TEMP3) 

             SELECT COUNT(*) 
             INTO iCount
             FROM TEMP_ALL 

             IF iCount > 0 THEN     
                     TEMP_OUT AS( 
                              SELECT Key1, count(*) as cnt 
                              FROM TEMP_ALL),  

                      TempKey AS(
                      SELECT BarSuid FROM TEMP_OUT
                      WHERE cnt = (SELECT MAX(cnt) FROM TEMP_OUT));
              ELSE
                   TempKey AS(
                   SELECT Key1 FROM PRODUCT 
                   WHERE Key1  NOT IN ( SELECT Key1  FROM PRODUCT_DET)); 
              END IF;              

               SELECT  key2
                  INTO PROD_KEY 
                  FROM PRODUCT,TempKey
                  WHERE PRODUCT.Key1 = TempKey.Key1 
                AND TempKey.Key1 IS NOT NULL;

EXCEPTION
    WHEN OTHERS
    THEN
        dbms_output.put_line(SQLCode);

    END;
4

2 回答 2

2

我不知道这是否只是更大程序的一部分或其他什么,您问题中的标记有点令人困惑。

无论如何,我注意到的是您在第一个SELECT的末尾忘记了分号 (;) 。它应该是:

SELECT COUNT(*) 
INTO   iCount
FROM   TEMP_ALL;
于 2009-08-16T06:12:53.467 回答
1

" WITH S600 AS (" 开始一条 SQL 语句,但后面的 (" Prod_KEY NUMBER; iCount NUMBER;") 是 PL/SQL。此外,WITH 不用于声明 SQL 语句 - 您可能正在考虑使用“ CURSOR xxx IS SELECT ...;”声明的显式游标。

您的 PL/SQL 块需要以 DECLARE 开头。例如:

DECLARE
    Prod_KEY NUMBER; iCount NUMBER;
BEGIN
    SELECT COUNT(*) 
    INTO iCount
    FROM (SELECT * FROM TEMP1
          UNION ALL SELECT * FROM TEMP2
          UNION ALL SELECT * FROM TEMP3);
    IF iCount > 0 THEN ...

我认为你应该能够从那里拿走它。

于 2009-08-14T06:43:18.240 回答