469,333 Members | 4,210 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,333 developers. It's quick & easy.

DECODE function

106 100+
i was asked in an interview to use the decode function to print High if salary was greater than 2500 and low if it was less than 2000... but i dont know how to use relational operators in decode ??!! is that possible ?? help plz
Apr 20 '07 #1
4 12854
Saii
145 Expert 100+
You can do it using CASE as it is an alterative for implemeting if-then-else logic in SQL statements.
Apr 20 '07 #2
DECODE is a power function, and that was a trick question.

Here are some details on DECODE on this link.
http://www.psoug.org/reference/decode_case.html
Apr 23 '07 #3
debasisdas
8,127 Expert 4TB
Use case within Decode

Since Expressions can't be used with decode

The output of case should be input for decode.

U can also do it using only CASE, no need of decode at all.

Expand|Select|Wrap|Line Numbers
  1. SELECT decode(
  2. CASE 
  3. WHEN sal>2500 THEN '1'
  4. WHEN sal<2000 THEN '2'
  5. END  ,'1','High','2','Lo') FROM EMP
  6.  
try on SCOTT schema EMP table
Apr 28 '07 #4
i was asked in an interview to use the decode function to print High if salary was greater than 2500 and low if it was less than 2000... but i dont know how to use relational operators in decode ??!! is that possible ?? help plz

As per the requirement, below script will print
Low for <2000
High for>2500
but null for 2000 to 2500


select decode(least(&salary,2000),2000,decode(greatest(&s alary,2500),&salary,'High'),'Low') print from dual
May 3 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Mark Hoffman | last post: by
10 posts views Thread by N | last post: by
2 posts views Thread by Amin Schoeib | last post: by
3 posts views Thread by Guoqi Zheng | last post: by
1 post views Thread by MP | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.