Swapping column values in Oracle

前端 未结 3 1630
再見小時候
再見小時候 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:12

    CREATE TABLE Names
    (
    F_NAME VARCHAR(22),
    L_NAME VARCHAR(22)
    );
    
    INSERT INTO Names VALUES('Ashutosh', 'Singh'),('Anshuman','Singh'),('Manu', 'Singh');
    
    UPDATE Names N1 , Names N2 SET N1.F_NAME = N2.L_NAME , N1.L_NAME = N2.F_NAME 
    WHERE N1.F_NAME = N2.F_NAME;
    
    SELECT * FROM Names;
    

提交回复
热议问题