Home » SQL & PL/SQL » SQL & PL/SQL » Interchange of Columns
Interchange of Columns [message #207131] Mon, 04 December 2006 04:26 Go to next message
inforacle
Messages: 21
Registered: December 2006
Junior Member
Hai,

It is known that we can rename a column, I want to know wth to Interchange two columns along with the data in a table.

ex:

EMP


X Y

1 a
2 b


i want the o/p as

Y X
a 1
b 2
Re: Interchange of Columns [message #207132 is a reply to message #207131] Mon, 04 December 2006 04:29 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
Imagine what would happen if you had to change the table's structure for each different select! The order of the columns is completely irrelevant in Oracle.

Lucky for us, you can tell Oracle the order of the select list:
select x, y from yourtable

select y, x from yourtable


MHE

[Updated on: Mon, 04 December 2006 04:30]

Report message to a moderator

Re: Interchange of Columns [message #207133 is a reply to message #207131] Mon, 04 December 2006 04:30 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
hi,

update table_name set col1=col2,col2=col1


regards,
Re: Interchange of Columns [message #207141 is a reply to message #207133] Mon, 04 December 2006 05:07 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
dhananjay wrote on Mon, 04 December 2006 11:30
hi,

update table_name set col1=col2,col2=col1


regards,

And change the column names as well. The header of the desired output the OP showed, tells us the CONTENTS of the columns should remain the same.
Re: Interchange of Columns [message #207148 is a reply to message #207141] Mon, 04 December 2006 05:28 Go to previous message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
hi,

totally misread the post.sorry for the that.



regards,
Previous Topic: outer join 2
Next Topic: Delete on child-table locks father-table
Goto Forum:
  


Current Time: Wed Dec 07 18:42:57 CST 2016

Total time taken to generate the page: 0.20445 seconds