Home > Database > Mysql Tutorial > mysql存储过程:复制表A的某列到表B中去_MySQL

mysql存储过程:复制表A的某列到表B中去_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:34:44
Original
935 people have browsed it

bitsCN.com

mysql存储过程:复制表A的某列到表B中去

 

这是一个存储过程,用于将tableA表中avalue列的值复制到tableB表中的bvalue列(假设tableA和tableB中都有相同的列,名为id)

 

[sql] 

create procedure copy_field()  

begin  

    declare tid int default 0;  

    declare tvalue int default 0;  

  

    declare b int default 0;  

    declare cur cursor for select a.id, a.avalue from tableA as a join tableB as b where a.id=b.id;  

    DECLARE CONTINUE HANDLER FOR NOT FOUND SET b = 1;  

  

    open cur;   

    set b = 0;  

    repeat  

        FETCH cur INTO tid, tvalue;  

        update tableB set bvalue=tvalue where id=tid;  

        until b>0  

    end repeat;  

    close cur;  

end  

 

bitsCN.com
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template