MySQL stored procedure copy a table data to table B

Source: Internet
Author: User

CREATE PROCEDURE Sys_message_user_for_busbase () Begin-Declares a flag done that is used to determine whether the cursor is traversing the completion of the DECLARE do INT DEFAULT 0; --Declare a variable to hold the data extracted from the cursor--especially note that the name cannot be the same as the column used in the cursor, otherwise the resulting data is null DECLARE tid varchar () DEFAULT null; DECLARE tname varchar () DEFAULT NULL; DECLARE thead varchar (255) DEFAULT NULL; DECLARE tmobile varchar (255) DEFAULT NULL; --Declares the SQL statement corresponding to the cursor DECLARE cur cursor FOR select Id,shop_name, Mobile_phone,shop_logo from Hx_busbase; --At the end of the cursor loop, the done is set to 1 DECLARE CONTINUE HANDLER for not FOUND set do = 1; --Execute Query open cur;  --iterate through each row of the cursor REPEAT--store a row of information in the corresponding variable FETCH cur into tid,tname, thead,tmobile; If not do then--here you can use Tname, tpass the corresponding information if (select COUNT (1) from hx_message_user where uid=tid) = 0 Theninsert in   To Hx_message_user (Id,head,mobile,username,uid,remark) VALUES (Tid,thead,tmobile,tname,tid, "busbase"); End if;  #select Tid,tname, Tpass, (select COUNT (1) from btable where Id=tid) as count;  End If; UNTIL done END REPEAT; CLOSE Cur;end
#执行
Call Sys_message_user_for_busbase ();

MySQL stored procedure copy a table data to table B

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.