Home » SQL & PL/SQL » SQL & PL/SQL » Decode Function
Decode Function [message #205680] Mon, 27 November 2006 01:50 Go to next message
ying
Messages: 143
Registered: May 2002
Senior Member
Hi,

Just wonder can we use decode as below:

SELECT supplier_name, supplier_id As sup_id
decode(sup_id
, 10000, 'IBM',
10001, 'Microsoft',
10002, 'Hewlett Packard',
'Gateway') result
FROM suppliers;

What I want here is use the variable name sup_id instead of column name. I did testing, but it failed and say that invalid column.

pls advise...


Re: Decode Function [message #205688 is a reply to message #205680] Mon, 27 November 2006 02:33 Go to previous message
Littlefoot
Messages: 20891
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
You are, actually, saying that many columns in the 'suppliers' table contain values 10000, 10001 and 10002 which represent a supplier ID and no matter what column you select, you'd like to get the supplier's name.

Are you sure that this is what you want? To me, it doesn't make any sense.

Besides, why do you need the DECODE function? You already have a 'supplier_name' column in this table.

What you could do is to use a variable instead of a column, but that would require a slight change of the query. Something like this:
SELECT supplier_name, supplier_id
FROM suppliers
WHERE supplier_id = &sup_id;

Previous Topic: About Picture Storage
Next Topic: Long raw to file
Goto Forum:
  


Current Time: Sun Dec 04 00:51:14 CST 2016

Total time taken to generate the page: 0.05463 seconds