简体   繁体   中英

Missing Keyword (ORA-00905) - Oracle SQL Case Statement

Good morning,

I was wondering if one of you could help me - should be fairly quick I'd imagine; I'm a newbie so prone to missing obvious things.

I have the below statement which is returning the aforementioned 905 error...any ideas?

Thanks in advance.

(CASE CONTACTS.TELEPHONE_NO_DAY
    WHEN CONTACTS.TELEPHONE_NO_DAY LIKE '07%'
    THEN CONTACTS.TELEPHONE_NO_DAY
    ELSE NULL
    END) TEL_DAY,
   (CASE CONTACTS.TELEPHONE_NO_EVE
    WHEN CONTACTS.TELEPHONE_NO_EVE LIKE '07%'
    THEN CONTACTS.TELEPHONE_NO_EVE
    ELSE NULL
    END) TEL_EVE

You're mixing up two ways of doing case. You either need:

CASE <expression>
WHEN <comparison expression> THEN <return expression>
...

or

CASE
WHEN <condition> THEN <return expression>
...

These are the 'simple' and 'searched' variants in the docs .

But as you can't use like in the first version, you need the second:

CASE
WHEN CONTACTS.TELEPHONE_NO_DAY LIKE '07%'
THEN CONTACTS.TELEPHONE_NO_DAY
ELSE NULL
END

You also don't need the brackets around the two case statements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM