In some cases while building the sql statements dynamically in some front end languages, we need to concatenate strings . While concatenation it is very difficult to merge strings like 'A' or '1'. Because single quote means different. In that case it is very easy to use chr(65) like to build dynamic SQL's . Any way it depends case by case.
If I put the Between clause in quotes, it tries to interpret it as a literal. Do you know exactly how to code a between in the decode? I can't find any literature on it specifically.
SELECT
DECODE(UPPER(SUBSTR(ACTIVITY_ID,2,1))
,'1','Water'
,BETWEEN 'A' and 'Z','Water'
,'2','Waste'
,'3','ToolA/ToolB'
,'5','Shared'
,'Unknown'
) fund
,activity_id
from
SCHEMA.TABLE_INFO
where table_id like 'C%'
SELECT case when UPPER(SUBSTR(ename,2,1)) = '1' then 'Fire'
when UPPER(SUBSTR(ename,2,1)) BETWEEN 'A' and 'M' then 'Water'
when UPPER(SUBSTR(ename,2,1)) BETWEEN 'L' and 'Z' then 'Waste' else 'Unknown' end from emp
Bookmarks