Oracle uses SQL statements to exchange the contents of a field in two records in a table

            Don't be too busy, cherish the true love right now (Ma Xiaojing sorry~)  

                

 

Table test
---------------
  id | i_order
---------------
   1 | 22
   2 | 23
---------------
The converted result is:
---------------
  id | i_order
---------------
   1 | 23
   2 | 22
---------------

The Oracle and SQLServer data statements are the same, the statements are as follows:

UPDATE test   
   SET i_order = (CASE 

                  WHEN id = 1 THEN 

                   (SELECT i_order FROM test WHERE id = 2)  

                  WHEN id = 2 THEN 

                   (SELECT i_order FROM test WHERE id = 1)  

                END)  

  WHERE id=1 OR id=2; 

 

Guess you like

Origin blog.csdn.net/s_sos0/article/details/131399233