Wednesday, March 16, 2011

Move values from one column to other in Oracle table

I have around 100,000 records in my Oracle table.

TableMaster
-----------
TabID
Column1
Column2

How do I update all the records so that Column1 values are moved to Column2, and Column2 values are moved to column1?

From stackoverflow
  • Would this work?

    UPDATE TableMaster SET Column1 = Column2, Column2 = Column1
    
    Tony Andrews : +1 yes it would
  • Modify the table, changing the column names.

    Tony Andrews : +1 Interesting lateral thinking!
    Jeffrey Kemp : +1, however this will also swap any constraints on the columns, for good or ill

0 comments:

Post a Comment