-
Expert Member
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
-
Junior Member
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.
-
Expert Member
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 ......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules