>데이터 베이스 >MySQL 튜토리얼 >mysql从一个表向另一个表转移数据的存储过程_MySQL

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB원래의
2016-06-01 13:37:48985검색

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
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.