Reputation: 37
Consider the following code:
Select FLAGS,
CASE FLAGS
WHEN 0 THEN "10000000"
WHEN 1 THEN "01000000"
WHEN 2 THEN "00100000"
WHEN 3 THEN "00010000"
WHEN 4 THEN "00001000"
WHEN 5 THEN "00000100"
WHEN 6 THEN "00000010"
WHEN 7 THEN "00000001"
ELSE "00000000"
END AS Test-W
FROM V_TEST
The above statement is throwing error as:
ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action: Error at Line: 14 Column: 17
My table name is V_TEST
, column name is FLAGS
. What am I doing wrong here?
Upvotes: 0
Views: 113
Reputation: 49062
Of course, CASE
is verbose and easy to interpret. You could also write the same query using DECODE
-
SELECT FLAGS,
DECODE(FLAGS,
0 , '10000000',
1 , '01000000',
2 , '00100000',
3 , '00010000',
4 , '00001000',
5 , '00000100',
6 , '00000010',
7 , '00000001',
'00000000')
AS TEST-W
FROM V_TEST
/
Upvotes: 1
Reputation: 13425
use single quote ` for the literal expressions
The column Test-W needs to be enclosed in dobule quote
Select FLAGS,
CASE FLAGS
WHEN 0 THEN '10000000'
WHEN 1 THEN '01000000'
WHEN 2 THEN '00100000'
WHEN 3 THEN '00010000'
WHEN 4 THEN '00001000'
WHEN 5 THEN '00000100'
WHEN 6 THEN '00000010'
WHEN 7 THEN '00000001'
ELSE '00000000'
END as "Test-W"
FROM V_TEST
Upvotes: 3