mysql 預存程序複製A表資料到B表

來源:互聯網
上載者:User

標籤:

create procedure sys_message_user_for_busbase()begin -- 聲明一個標誌done, 用來判斷遊標是否遍曆完成 DECLARE done INT DEFAULT 0; -- 聲明一個變數,用來存放從遊標中提取的資料 -- 特別注意這裡的名字不能與由遊標中使用的列明相同,否則得到的資料都是NULL DECLARE tid varchar(50) DEFAULT NULL; DECLARE tname varchar(50) DEFAULT NULL; DECLARE thead varchar(255) DEFAULT NULL; DECLARE tmobile varchar(255) DEFAULT NULL; -- 聲明遊標對應的 SQL 陳述式 DECLARE cur CURSOR FOR select id,shop_name, mobile_phone,shop_logo from hx_busbase; -- 在遊標迴圈到最後會將 done 設定為 1 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; -- 執行查詢 open cur; -- 遍曆遊標每一行 REPEAT  -- 把一行的資訊存放在對應的變數中  FETCH cur INTO tid,tname, thead,tmobile;  if not done then   -- 這裡就可以使用 tname, tpass 對應的資訊了if (select count(1) from hx_message_user where uid=tid) = 0 THENINSERT INTO 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 預存程序複製A表資料到B表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.