执行case语句时出错

时间:2012-11-20 14:58:09

标签: sql oracle10g

我正在尝试执行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%'

我错过了哪些关键字?

由于

2 个答案:

答案 0 :(得分:2)

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

相反,将CASE语句作为逻辑测试的一部分。比如...

code_branch.branch_code1
like
case :input1 when 'ABB'  Then '%0232%'
             when 'AiBB' Then '%0347%' end

答案 1 :(得分:0)

尝试这个

SELECT ....
FROM...
WHERE ....
AND
(
    ((:input1 = 'ABB') AND code_branch.branch_code1 like '%0232%') OR
    ((:input1 = 'AiBB') AND code_branch.branch_code1 like '%0347%')
)