生命不是要超越别人,而是要超越自己。每天醒来并告诉自己:更少的理由,更大的腹部,更甜的嘴,更小的脾气,更快的动作,更高的效率,一点微笑和脑。一站式
-- 建立测试表和数据
create table webuser (username varchar(10));
insert into webuser values ('a1'),('a2'),('a3'),('b1'),('b2'),('b3');
commit;-- 建立存储过程
drop procedure if exists dynamic_cursor;
delimiter //
CREATE PROCEDURE dynamic_cursor (IN p_name varchar(10))
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE v_username varchar(10);
DECLARE cur CURSOR for( SELECT username from webuser_view);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;DROP VIEW IF EXISTS webuser_view;SET @sqlstr = "CREATE VIEW webuser_view as ";
SET @sqlstr = CONCAT(@sqlstr , "SELECT username FROM webuser WHERE username like '", p_name,"%'");PREPARE stmt FROM @sqlstr;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;OPEN cur;
f_loop:LOOP
FETCH cur INTO v_username;
IF done THEN
LEAVE f_loop;
END IF;
SELECT v_username;
END LOOP f_loop;
CLOSE cur;
END;
//
delimiter ;-- 测试
call dynamic_cursor('a');
到此这篇关于mysql动态游标学习(mysql存储过程游标)就介绍到这了。人为善,福虽未至,祸已远离;人为恶,祸虽未至,福已远离。更多相关mysql动态游标学习(mysql存储过程游标)内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!