Home » SQL & PL/SQL » SQL & PL/SQL » Using DECODE function in UPDATE statement
Using DECODE function in UPDATE statement [message #20813] Sun, 23 June 2002 03:15 Go to next message
Azzah Al-Sayegh
Messages: 3
Registered: June 2002
Junior Member
Can I use the DECODE function to minimize the below coding?

IF condition = A THEN
UPDATE table_T
SET col_A = X;
ELSIF condition = B
UPDATE table_T
SET col_B = X;
ELSIF condition = C
UPDATE table_T
SET col_C = X;
ELSE
UPDATE table_T
SET col_D = X;
END IF;

Please note that I am updating different columns in the same table according to cetrain condition.

Thanks.
Re: Using DECODE function in UPDATE statement [message #20815 is a reply to message #20813] Sun, 23 June 2002 10:40 Go to previous messageGo to next message
Pablo Martinez
Messages: 2
Registered: June 2002
Junior Member
Hello.

Perhaps something like this could work:

UPDATE table_T
SET col_A = DECODE (condition,A,X,NULL),
col_B = DECODE (condition,B,X,NULL),
col_C = DECODE (condition,C,X,NULL),
col_D = DECODE (condition,D,X,NULL);

Hope this helps
Regards, Pablo
Re: Using DECODE function in UPDATE statement [message #21777 is a reply to message #20813] Wed, 28 August 2002 23:46 Go to previous message
Bidyut
Messages: 1
Registered: August 2002
Junior Member
Hi Buddy....
U can use the decode function in the above query if ur condition is same (value might be different)

Check it...

update table_T
set decode(condition, 'A', 'col_A','B','Col_B',...)='X'
Previous Topic: Creation of Temp table
Next Topic: Executing a sql script in the command prompt and getting the output in a file
Goto Forum:
  


Current Time: Thu Apr 25 05:11:13 CDT 2024