2014-05-10 145 views
-1

而執行這個查詢,我得到錯誤'ORA-00905: missing keyword',誤差的情況下,statement..Please找到一個解決方案 請在下面找到「ORA-00905:缺少關鍵字」

SELECT Count(*) 
FROM c_bpartner 



WHERE c_bpartner.issummary = 'N' 
     AND c_bpartner.isactive = 'Y' 
     AND c_bpartner.isactive = 'Y' 
     AND c_bpartner.issummary = 'N' 
     AND (CASE 
       WHEN 135 NOT IN (SELECT c_doctype_id 
           FROM c_doctype 
           WHERE docsubtypeso IN('OB', 'ON')) THEN 
       c_bpartner.isprospect = 'N' 
       ELSE c_bpartner.isprospect = 'Y' 
        OR c_bpartner.isprospect = 'N' 
      END) 
     AND c_bpartner.iscustomer = 'Y' 
     AND c_bpartner.isprospect = 'N' 
+2

我爲您清理了您的問題,下次將您的代碼包裝在代碼標記中並在發佈之前美化您的SQL,謝謝。 –

回答

2

查詢,我相信這個問題與WHERE條款中的CASE聲明一致。您正嘗試應用可選過濾器,但CASE不允許您對查詢應用動態更改。相反,使用CASE來投影可以在謂詞中使用的行特定值,例如,假設「Y」和「N」是isprospect唯一的可能性,嘗試重寫的情況下,像這樣:

AND c_bpartner.isprospect = 
(CASE 
    WHEN 135 NOT IN (SELECT c_doctype_id 
        FROM c_doctype 
        WHERE docsubtypeso IN('OB', 'ON')) 
    THEN 
     'N' 
    ELSE 
     c_bpartner.isprospect 
    END 
) 

ELSE返回c_bpartner.isprospect應保證匹配。