Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql stored procedure to move tables

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Achieve simple table movement and use cursor loops

The first line DELIMITER / / and the last line / / must, otherwise an error will be reported if you encounter a semicolon

DELIMITER / / create procedure movedata () BEGIN DECLARE Done INT DEFAULT 0; DECLARE v_id VARCHAR (30); / * declare cursors * / DECLARE rs CURSOR FOR SELECT id FROM `new`.customer; / * exception handling * / DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' customer = 1; / * Open cursors * / OPEN rs / * to extract the value of the LingQi field of the current record one by one, you need to determine the maximum value * / FETCH rs INTO vroomid; / * traverse the data table * / REPEAT IF NOT Done THEN insert into `old`.customer (id,idcard_no) (select id+100000,idcard_no from `new`.customer where id = v_id); END IF FETCH rs INTO vault; UNTIL Done END REPEAT; / * close cursors * / CLOSE rs; END / /

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report