Swapping column values in Oracle

前端 未结 3 1607
再見小時候
再見小時候 2021-02-19 10:25

I was solving one of the puzzles and came across swapping column values using DML queries:

SELECT * FROM TEMP_TABLE;
ID1, ID2
--------
20, 15
20, 15
20, 15
         


        
3条回答
  •  再見小時候
    2021-02-19 11:09

    Before:

    select * from employ;
    
    EMPNO FNAME      LNAME
    ----- ---------- ----------
     1001 kiran      kumar
    
     1002 santosh    reddy
    
    
    update employ e set fname=(select lname from employ where empno=e.empno),
                        lname=(select fname from employ where empno=e.empno);
    

    After:

     select * from employ;
    
     EMPNO FNAME      LNAME
    ------ ---------- ----------
      1001 kumar      kiran
    
      1002 reddy      santosh
    

提交回复
热议问题