我在执行此查询时收到错误'ORA-00905: missing keyword'
,错误是在case语句中。请找到解决方案
请找到下面的查询
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'
答案 0 :(得分:2)
我认为问题在于CASE
条款中的WHERE
声明。您正在尝试应用可选过滤器,但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
)
在c_bpartner.isprospect
中返回ELSE
应保证匹配。