• 欢迎访问小杰博客网站
  • 欢迎访问小杰博客网站哦

存储过程循环阅读记录表

mysql 小杰 3个月前 (01-04) 183次浏览 已收录 0个评论

drop PROCEDURE if exists book_read_records;
CREATE PROCEDURE book_read_records(In in_bid INT)
BEGIN

DECLARE i INT;
DECLARE TABLE_NAME VARCHAR(20);
DECLARE table_pre VARCHAR(20);
DECLARE sql_text VARCHAR(2000);
SET i=0;
SET TABLE_NAME=”;
SET table_pre=’record_records’;
SET sql_text=”;

WHILE i<2048 DO

SET TABLE_NAME=CONCAT(table_pre,i);

SET sql_text=CONCAT(‘REPLACE INTO temp_records.book_read_records(bid,cid,uid,distribution_channel_id,sequence,created_at,updated_at) SELECT b.bid,b.cid,b.uid,b.distribution_channel_id,b.sequence,b.created_at,b.updated_at FROM user_read_records.’,TABLE_NAME,’ b WHERE b.bid=’,in_bid,’ GROUP BY b.bid,b.uid,b.sequence’);

SELECT sql_text;
SET @sql_text=sql_text;
PREPARE stmt FROM @sql_text;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET i=i+1;

END WHILE;
END

CALL book_read_records(13922);
SELECT * from temp_records.book_read_records;


小杰博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:存储过程循环阅读记录表
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址