2017-02-28 139 views
-2

當編譯下面的SQL-Procedure時,我在第10行發現錯誤,該錯誤恰好是SELECT NVL(LOGNO, 0) LOGNO行,說SQL Statement ignored。我不知道爲什麼會出現這個錯誤。忽略PL/SQL過程語句

我不太確定的另一件事是WHERE子句它也引發了一個錯誤:這是在PIVOT線上提出的。在WHERE子句末尾添加;不會有幫助。

有什麼建議嗎?

PROCEDURE p_get_stmfrd_rel_records(pc_recordset IN OUT SYS_REFCURSOR, 
             ps_ReleaseId VARCHAR2) 

    IS 

    BEGIN 
     OPEN pc_recordset FOR 
     SELECT NVL(LOGNO, 0) LOGNO    -- SQL Statement ignored 
       ,NVL(INSTANCENO, 0) INSTANCENO 
       ,RELEASE_BUILD 
       ,SCRIPT_NAME 
       ,NVL(VERSION, 0) VERSION 
       ,NVL(REQUEST, 0) REQUEST 
       ,COMMENTS 
       ,NVL(GLUSDBT1_DEPLOYDATE, '1-Jan-0001') GLUSDBT1_DEPLOYDATE 
       ,NVL(GLUSDBR1_DEPLOYDATE, '1-Jan-0001') GLUSDBR1_DEPLOYDATE 
       ,NVL(GLUSDBP1_DEPLOYDATE, '1-Jan-0001') GLUSDBP1_DEPLOYDATE 
      FROM (SELECT dlog.LOGNO 
       ,DLOGDET.INSTANCENO 
       ,DLOG.RELEASEID AS RELEASE_BUILD 
       ,DLOG.FILENAMEEXT_VC AS SCRIPT_NAME 
       ,DLOG.VERSION 
       ,DLOG.REQUEST 
       ,DLOG.NOTE AS COMMENTS 
       ,DLOGDET.DEPLOYDATE 
       ,INST.INSTANCEID    
        FROM ADM_DEPLOYMENTLOG DLOG 
         JOIN ADM_DEPLOYMENTLOGDETAIL DLOGDET 
          ON DLOG.LOGNO = DLOGDET.LOGNO AND DLOGDET.CANCELEDIND = 'N' 
         LEFT OUTER JOIN ADM_INSTANCE INST 
          ON  DLOGDET.INSTANCENO = INST.INSTANCENO 
           AND INST.SITEID = 'STM' 
           AND INST.CANCELEDIND = 'N') 

       WHERE (DLOG.RELEASEID IS NULL AND ps_ReleaseId = "1900-01") 
       OR (DLOG.RELEASEID IS NOT NULL AND DLOG.RELEASEID = ps_ReleaseId) 

       PIVOT      -- SQL command not properly ended 
        (MAX (TRUNC (DEPLOYDATE)) 
        AS DEPLOYDATE 
        FOR INSTANCEID 
        IN ('GLUSDBT1' AS GLUSDBT1 
        ,'GLUSDBR1' AS GLUSDBR1 
        ,'GLUSDBP1' AS GLUSDBP1));  
    END p_get_stmfrd_rel_records; 
+1

'where'子句需要在'pivot'之後去。另外,''1900-01''應該是''1900-01'',除非有一個名爲''1900-01''的列或函數。 (另外,如果'GLUSDBT1_DEPLOYDATE'是一個日期,那麼你可能不應該將它與字符串混合,比如''Jan-0001-'')。 –

+1

編譯錯誤很難解決,因爲我們無法訪問數據庫模式。一個更好的方法是讓你去除你的代碼中的一個基本查詢。獲得編譯和工作,然後添加不同的位,直到找到打破它的東西。 – APC

回答

0

這是錯誤的:

// SQL command not properly ended

在PLSQL您可以發表評論使用雙破折號線( - )或/ *這裏的任何書面之間的任何事情都會被註釋*/

-- line will be commented 
or /* anything here will be commented*/ 

理解真正的問題後編輯。按照William的建議嘗試此建議

PROCEDURE p_get_stmfrd_rel_records (pc_recordset IN OUT SYS_REFCURSOR, 
            ps_ReleaseId   VARCHAR2) 
IS 
BEGIN 
    OPEN pc_recordset FOR 
     SELECT NVL (LOGNO, 0) LOGNO, 
      NVL (INSTANCENO, 0) INSTANCENO, 
      RELEASE_BUILD, 
      SCRIPT_NAME, 
      NVL (VERSION, 0) VERSION, 
      NVL (REQUEST, 0) REQUEST, 
      COMMENTS, 
      NVL (GLUSDBT1_DEPLOYDATE, '1-Jan-0001') GLUSDBT1_DEPLOYDATE, 
      NVL (GLUSDBR1_DEPLOYDATE, '1-Jan-0001') GLUSDBR1_DEPLOYDATE, 
      NVL (GLUSDBP1_DEPLOYDATE, '1-Jan-0001') GLUSDBP1_DEPLOYDATE 
     FROM (SELECT dlog.LOGNO, 
        DLOGDET.INSTANCENO, 
        DLOG.RELEASEID AS RELEASE_BUILD, 
        DLOG.FILENAMEEXT_VC AS SCRIPT_NAME, 
        DLOG.VERSION, 
        DLOG.REQUEST, 
        DLOG.NOTE AS COMMENTS, 
        DLOGDET.DEPLOYDATE, 
        INST.INSTANCEID 
       FROM ADM_DEPLOYMENTLOG DLOG 
        JOIN ADM_DEPLOYMENTLOGDETAIL DLOGDET 
         ON  DLOG.LOGNO = DLOGDET.LOGNO 
          AND DLOGDET.CANCELEDIND = 'N' 
        LEFT OUTER JOIN ADM_INSTANCE INST 
         ON  DLOGDET.INSTANCENO = INST.INSTANCENO 
          AND INST.SITEID = 'STM' 
          AND INST.CANCELEDIND = 'N')      
      PIVOT      
        (MAX (TRUNC (DEPLOYDATE)) 
        AS DEPLOYDATE 
        FOR INSTANCEID 
        IN ('GLUSDBT1' AS GLUSDBT1 
        ,'GLUSDBR1' AS GLUSDBR1 
        ,'GLUSDBP1' AS GLUSDBP1))      
      WHERE (DLOG.RELEASEID IS NULL AND ps_ReleaseId = '1900-01') 
      OR (DLOG.RELEASEID IS NOT NULL AND DLOG.RELEASEID = ps_ReleaseId)    ; 
    END p_get_stmfrd_rel_records; 
+0

感謝XING,但我只是爲你添加了這些註釋,以查看錯誤出現在哪裏,它們不在實際代碼中,因此不是錯誤的原因。 –