Home >Database >Mysql Tutorial >mysql从一个表向另一个表转移数据的存储过程_MySQL

mysql从一个表向另一个表转移数据的存储过程_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:37:48989browse

bitsCN.com

mysql从一个表向另一个表转移数据的存储过程

 

DELIMITER $$    

USE `sms`$$

DROP PROCEDURE IF EXISTS `sendSmsProcs`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sendSmsProcs`(numberArrayId CHAR(32),longSmsId CHAR(32))

BEGIN

 

 /*创建临时表   放要下发的临时组数据*/

 CREATE TEMPORARY TABLE tmp_table(phonenumber CHAR(11))TYPE = HEAP;

 TRUNCATE TABLE tmp_table;

 CREATE UNIQUE INDEX tmp_table_index ON tmp_table(phonenumber);

     

 /* 放入临时组数据*/

 INSERT INTO tmp_table SELECT phoneNumber FROM smsallphone WHERE smsallphone.numberArrayId = numberArrayId;

 

 SELECT COUNT(*) FROM tmp_table;

 

 /*创建临时表 查询出大发表中已经存在的号码 */

 CREATE  TEMPORARY TABLE tmp_table2(phonenumber CHAR(11)) TYPE = HEAP; 

 TRUNCATE TABLE tmp_table2;

 CREATE UNIQUE INDEX tmp_table2_index ON tmp_table2 (phonenumber);

 

 /*  放入临时数据  待发表中已经存在的用户号码 */

 INSERT INTO tmp_table2 SELECT  tmp_table.phonenumber FROM tmp_table,smssystem WHERE tmp_table.phonenumber= smssystem.phoneNumber ;

 

 SELECT COUNT(*) FROM tmp_table2;

 /* 删除已经存在的待发表中的数据*/

 DELETE FROM tmp_table WHERE tmp_table.phonenumber IN (SELECT phonenumber FROM tmp_table2);

 INSERT INTO smssystem SELECT replace(uuid(),'-',''),longSmsId,phonenumber,sysdate(),sysdate(),0,0,0 FROM tmp_table;

 

    END$$

DELIMITER ;

 

bitsCN.com
Statement:
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