MYSQL使用存储过程查询其他表数据更新另一张表

-- ----------------------------
-- Procedure structure for rpadownloadmanage
-- ----------------------------
DROP PROCEDURE IF EXISTS `rpadownloadmanage`;
delimiter ;;
CREATE PROCEDURE `rpadownloadmanage`()
BEGIN

	DECLARE ASCENECODE VARCHAR(50) DEFAULT "";
	DECLARE AUGID VARCHAR(150) DEFAULT "";
	DECLARE AYHDM int(10) DEFAULT 0;
	DECLARE AVERSION VARCHAR(36) DEFAULT "";
	DECLARE AXSMC VARCHAR(36) DEFAULT "";
	DECLARE AORGNAME VARCHAR(36) DEFAULT "";

	DECLARE done INT DEFAULT 0;
	DECLARE scene cursor for SELECT SCENECODE, VERSION, UGID,YHDM,XSMC,ORGNAME FROM T_PORTAL_RPA_SCENE GROUP BY SCENECODE, VERSION;
	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
	open scene;
	
	REPEAT

	fetch scene into ASCENECODE, AVERSION, AUGID,AYHDM,AXSMC,AORGNAME;
	
	if not done THEN
	UPDATE RPADOWNLOADMANAGE SET UGID = AUGID, YHDM=AYHDM, XSMC=AXSMC, ORGNAME=AORGNAME WHERE  ROBOTID=ASCENECODE AND VERSION = AVERSION;
	end if;
	until done end repeat;

close scene;
commit;
END
;;
delimiter ;

call rpadownloadmanage();
posted @ 2021-12-24 14:41  昨夜风雨声  阅读(40)  评论(0编辑  收藏  举报  来源