Copy values from one column to another in the same table

前端 未结 7 1671
别那么骄傲
别那么骄傲 2020-12-02 05:08

How can I make a copy values from one column to another? I have:

Database name: list
number | test
123456 | somedata
123486 | somedata1
232344 | 34
         


        
7条回答
  •  长情又很酷
    2020-12-02 05:26

    you can do it with Procedure also so i have a procedure for this

     DELIMITER $$
     CREATE PROCEDURE copyTo()
           BEGIN
                   DECLARE x  INT;
                DECLARE str varchar(45);
                  SET x = 1;
                set str = '';
                  WHILE x < 5 DO
                    set  str = (select source_col from emp where id=x);
                update emp set target_col =str where id=x;      
                SET  x = x + 1;
                    END WHILE;
    
           END$$
       DELIMITER ;
    

提交回复
热议问题