Home » SQL & PL/SQL » SQL & PL/SQL » How to swap data of two colums for same table using only one query
How to swap data of two colums for same table using only one query [message #185395] Tue, 01 August 2006 09:16 Go to next message
jilhewar_santosh
Messages: 13
Registered: July 2006
Location: mumbai
Junior Member
suppose i have table
create table emp(x varchar2(10),y varchar2(10))
insert into emp values(10,20);
insert into emp values(30,40);
insert into emp values(50,60);
insert into emp values(70,80);
select * from emp
x y
-------
10 20
30 40
50 60
70 80
now i want data like
x y
-------
20 10
40 30
60 50
80 70
so how i do this using only one query


Re: How to swap data of two colums for same table using only one query [message #185397 is a reply to message #185395] Tue, 01 August 2006 09:26 Go to previous messageGo to next message
navkrish
Messages: 189
Registered: May 2006
Location: NJ,USA
Senior Member

Instead of writing a query, I would rather rename the column names...

Naveen
Re: How to swap data of two colums for same table using only one query [message #185402 is a reply to message #185395] Tue, 01 August 2006 09:48 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Have you tried
UPDATE emp
SET x = y, y = x

Works fine for me...
Re: How to swap data of two colums for same table using only one query [message #185469 is a reply to message #185402] Tue, 01 August 2006 22:36 Go to previous message
jilhewar_santosh
Messages: 13
Registered: July 2006
Location: mumbai
Junior Member
hi JRowbottom
thank u for u r solution
Previous Topic: DML through view
Next Topic: Concurrency in dynamic query using sys_context
Goto Forum:
  


Current Time: Sat Dec 03 05:58:54 CST 2016

Total time taken to generate the page: 0.13615 seconds