1

我正在尝试执行 case 语句,但出现错误。这是我的查询

select LOSA_APP.app_ref_no AS "App.Ref.No.",  CODE_BRANCH.branch_name AS "BRANCH"
from losa_app LOSA_APP
INNER JOIN
    losa_app_z LOSA_APP_Z  
ON
    losa_app.app_ref_no = losa_app_z.app_ref_no 
INNER JOIN
    code_branch CODE_BRANCH
ON
    LOSA_APP.attend_branch = CODE_BRANCH.branch_id
where 
    LOSA_APP.app_status='A' -- Application Status in {‘accepted’} 
and 
    trunc(sysdate) between (nvl(LOSA_APP_Z.li_dt, LOSA_APP_Z.li_collect_dt)) AND ((trunc(sysdate))) -- falling under the reporting period
and
    (trunc(sysdate) - nvl(losa_app_z.li_dt,losa_app_z.li_collect_dt)) > 90  -- select application cases at any step after entering Documentation flows.
and 
    losa_app.product_type = 'MG' -- Select records based on input parameter value passed in. 
and
    case :input1
        when 'ABB' Then code_branch.branch_code1 like '%0232%'
        when 'AiBB' Then code_branch.branch_code1 like '%0347%'
    end

在执行时它要求我输入。之后它给了我错误

ORA-00905: missing keyword
00905. 00000 -  "missing keyword"
*Cause:    
*Action:
Error at Line: 22 Column: 50

第 22 行是when 'ABB' Then code_branch.branch_code1 like '%0232%'

我缺少什么关键字?

谢谢

4

2 回答 2

2

不要尝试从 CASE 语句返回逻辑布尔值。

相反,使 CASE 语句成为逻辑测试的一部分。如...

code_branch.branch_code1
like
case :input1 when 'ABB'  Then '%0232%'
             when 'AiBB' Then '%0347%' end
于 2012-11-20T15:01:10.693 回答
0

试试这个

SELECT ....
FROM...
WHERE ....
AND
(
    ((:input1 = 'ABB') AND code_branch.branch_code1 like '%0232%') OR
    ((:input1 = 'AiBB') AND code_branch.branch_code1 like '%0347%')
)
于 2012-11-20T15:02:48.693 回答