473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 13169
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

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

Similar topics

1
by: Walt | last post by:
Hi, I want to write a query that returns Y or N depending on whether the current time is within a specified window i.e. EVENT_TABLE ---------- event_id number PK event_start date...
2
by: Mark Hoffman | last post by:
I'm a newbie at Oracle..Be gentle! I have a table that stores information (WMI data) about computers on our network. The table looks like: ComputerID ItemID Class Property Value
10
by: N | last post by:
What is the function in SQL that works like DECODE in Oracle?" Thanks, N
4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
2
by: Amin Schoeib | last post by:
Hi, Like I see there is no equivalent to the Oracle decode Function In Postgres.Is there maybe somebody who wrote decode as a Function? Schoeib 4Tek Gesellschaft für angewandte...
3
by: Guoqi Zheng | last post by:
Dear sir, I need to decode base64 encoded email. I used below function but it does not work correctly, especially when I need to decode some Characters like Chinese, Can some one point out...
1
by: MP | last post by:
I have the following command. SELECT A.STORE_NAME, A.STORE_NUM, A.ZIP_CODE, B.EMPLOYEE_ID, B.GENDER, B.EMP_LEVEL, C.ITEM_CODE, DECODE(B.ITEM_CODE,1, 'CHICK_BURGERS') ITEM_DESCR,...
2
by: rsd | last post by:
Hi, I'm trying get Samsung YH-920 mp3 player to work with Debian GNU/Linux. To do that I need to run http://www.paul.sladen.org/toys/samsung-yh-925/yh-925-db-0.1.py script, the idea behind the...
1
by: Deven Oza | last post by:
Hello everyone Please help me for the following query I want to solve the query Using the (DECODE) function, I want to write a program segment that will successfully decode all the CIS courses...
16
by: Medhatithi | last post by:
Hi, I am facing a strange problem with decode function in oracle. My table name is status_hist. Below is the query I am hitting on this table: select...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.