Fork me on GitHub

mysql 存储过程

DROP PROCEDURE IF EXISTS sp_name;
create procedure sp_name()
BEGIN 
DECLARE suozaizhuji VARCHAR(32);
DECLARE base_ip VARCHAR(32);
DECLARE s int DEFAULT 0;
DECLARE baseip CURSOR FOR SELECT ip from base ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET s=1;

OPEN baseip;
FETCH baseip INTO base_ip;
while s <> 1 DO
select `所在主机` into suozaizhuji from VM where `IP地址` like CONCAT('%',base_ip,'%');
UPDATE base set `物理服务器名`= suozaizhuji where IP=base_ip;
FETCH baseip INTO base_ip;
end WHILE;
CLOSE baseip;
END

  

posted @ 2020-06-17 16:42  神雕爱大侠  阅读(148)  评论(0编辑  收藏  举报