René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
CASE WHEN [Oracle SQL] | ||
case when x = y then a else b end case when x < y then a when x = y then b else c end case XYZ when 'foo' then 'moo' else 'bar' end
The following little SQL script demonstrates the use of CASE WHEN.
create table test_case_when ( a varchar2(5), b varchar2(5) ); insert into test_case_when values ('*','*'); insert into test_case_when values ('+','+'); insert into test_case_when values ('-','-'); insert into test_case_when values ('.','.'); select a, case when b = '*' then 'star' when b = '+' then 'plus' when b = '-' then 'minus' else '????' end from test_case_when;
This select statement produces the following output:
A CASEW ----- ----- * star + plus - minus . ???? drop table test_case_when;
See also decode.
Thanks
Thanks to William S. Cressman who notified me of an error on this page which is now corrected.
|