Hi All,
Im new to decode function and trying to learn how to use decode function instead of case stateement.I have taken common table that is present in oracle database 'EMP'.for the below enames im trying to display specific location that is mentioned in decode condition but im not getting the proper result and throwing error ..I have consider below enames based for use on like condition mentioned below for the below empnames i want to display specifci location names mentioned in my decode script and for remaining enames it should be display location as null
Input values:
select EMPNO,ENAME FROM emp
where ename like 'S%' OR
ename like 'A%' OR
ename like 'J%' OR
ename like 'M%' OR
ename like 'B%'
order by ename asc
empno | ename |
7876 | ADAMS |
7499 | ALLEN |
7698 | BLAKE |
7900 | JAMES |
7566 | JONES |
7654 | MARTIN |
7934 | MILLER |
7788 | SCOTT |
7369 | SMITH |
Script used to get below output but im getting error.how to achieve below output by using decode function instead of case and if conditions.
select empno,ename,decode(ename,'S%','SA','A%,'ASIA','J%','JAPAN','M%','MALASIA','B%','BANGALORE') as LOCATIONS from emp
output:
empno | ename | Locations |
7876 | ADAMS | ASIA |
7499 | ALLEN | ASIA |
7698 | BLAKE | BANGALORE |
7900 | JAMES | JAPAN |
7566 | JONES | JAPAN |
7654 | MARTIN | MALASIA |
7934 | MILLER | MALASIA |
7788 | SCOTT | SA |
7369 | SMITH | SA |