《Mysql必读mysql动态游标与mysql存储过程游标(示例)》要点:
本文介绍了Mysql必读mysql动态游标与mysql存储过程游标(示例),希望对您有用。如果有疑问,可以联系我们。
-- 树立测试表和数据
create table webuser (username varchar(10));
insert into webuser values ('a1'),('a2'),('a3'),('b1'),('b2'),('b3');
commit;MYSQL学习
-- 建立存储进程
drop procedure if exists dynamic_cursor;
delimiter // www.jbxue.com
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;MYSQL学习
DROP VIEW IF EXISTS webuser_view;MYSQL进修
SET @sqlstr = "CREATE VIEW webuser_view as ";
SET @sqlstr = CONCAT(@sqlstr , "SELECT username FROM webuser WHERE username like '", p_name,"%'");MYSQL进修
PREPARE stmt FROM @sqlstr;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;MYSQL进修
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 ;MYSQL进修
-- 测试
call dynamic_cursor('a');MYSQL进修
维易PHP培训学院每天发布《Mysql必读mysql动态游标与mysql存储过程游标(示例)》等实战技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培养人才。