Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Two columns - exchange
A copy of this was sent to "sikh" <sikh_at_friko5.onet.pl>
(if that email address didn't require changing)
On Mon, 18 Jan 1999 21:05:33 GMT, you wrote:
>Hello !
>
>I am learning Oracle and SQL - (english too :)) and I have a problem. How
>can I exchange the values of two columns named "name" and "address". Both
>are varchar2(200) and both are existing in the same table "emp".
>Help, please ;)
>
>Piotr
>sikh_at_friko5.onet.pl
>
A simple: "update t set a = b, b = a;" will swap them
SQL> create table t ( a int, b int );
Table created.
SQL> insert into t values (1,2);
1 row created.
SQL> insert into t values (3,4);
1 row created.
SQL> update t set a = b, b = a;
2 rows updated.
SQL> select * from t;
A B
---------- ----------
2 1 4 3
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Service Industries
Reston, VA USA
--
http://govt.us.oracle.com/ -- downloadable utilities
Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Mon Jan 18 1999 - 19:55:26 CST