You Asked
Tom,
What is the true distinction between a CASE "Expression" and a CASE "Statement"?
Is it simply that the "Statement" version allows a sequence of statements after each WHEN clause? It appears that an ELSE is not necessarily needed with the "Expression" version, whereas an ELSE or exception handler needs to be included with the "Statement" version?
Is there a preference to use one over the other?
Thanks.
and Tom said...
they are synonymous.
there is a searched case and a non-searched case, but a "case statement" is the same as a "case expression"
1 select user_id,
2 case user_id
3 when 5
4 then 'five'
5 else 'not five'
6 end searched_case,
7 case when user_id <> 5
8 then 'not five'
9 when user_id is not null
10 then 'five'
11 end not_searched_case
12 from all_users
13* where user_id <= 10
ops$tkyte@ORA10GR2> /
USER_ID SEARCHED NOT_SEAR
---------- -------- --------
0 not five not five
5 five five
Neither "mandates" an else:
1 select user_id,
2 case user_id
3 when 5
4 then 'five'
5 end searched_case,
6 case when user_id <> 5
7 then 'not five'
8 when user_id is not null
9 then 'five'
10 end not_searched_case
11 from all_users
12* where user_id <= 10
ops$tkyte@ORA10GR2> /
USER_ID SEAR NOT_SEAR
---------- ---- --------
0 not five
5 five five
Rating
(3 ratings)
Is this answer out of date? If it is, please let us know via a Comment