Geeks Talk

Prepare for your Next Interview




Cyclic Updating

This is a discussion on Cyclic Updating within the Oracle forums, part of the Databases category; There is a table Table_A contains 4 feilds col1, col2, col3, col4 having values a, b, c, d as values respectively. What will be the code if someone wants to ...


Go Back   Geeks Talk > Databases > Oracle

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-12-2007
Expert Member
 
Join Date: Oct 2006
Posts: 690
Thanks: 0
Thanked 46 Times in 39 Posts
JobHelper is on a distinguished road
Cyclic Updating

There is a table Table_A contains 4 feilds col1, col2, col3, col4 having values a, b, c, d as values respectively. What will be the code if someone wants to update a with b, b with c, c with d and d with a ?

NOTE : This question was asked by sha_jit
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-14-2007
Junior Member
 
Join Date: Jan 2007
Location: Chennai
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Bhuvana07 is on a distinguished road
Re: Cyclic Updating

Hai,

how abt this code?

begin
select col1 into :temp from table_1 where col1 = 'a';
update table_1 set col1=col2,col2=col3,col3=col4,col4=:temp where col1='a';
end;


here, ":temp" is the bind variable. This code is very specific to the question.
This works when col2's datatype is compatible with the col1's datatype and so..

And may I know where we could find situation like this?

Regards,
Bhuvana.
Reply With Quote
  #3 (permalink)  
Old 10-13-2007
Expert Member
 
Join Date: Apr 2007
Posts: 404
Thanks: 13
Thanked 52 Times in 52 Posts
susarlasireesha is on a distinguished road
Re: Cyclic Updating

Update cyclic1 set col1= decode(col1,'a','b'),col2=decode(col2,'b','c'),col3=decode(col3,'c','d'),
col4=decode(col4,'d','a')
or
Update cyclic1 set col1= decode(col1,col1,col2),col2=decode(col2,col2,col3),col3=decode(col3,col3,col4),
col4=decode(col4,col4,col1)
Try this ......
Reply With Quote
Reply

  Geeks Talk > Databases > Oracle


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Updating table with group of line items Lokesh M SAP R/3 0 12-10-2006 05:47 AM


All times are GMT -4. The time now is 02:06 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved