Mysql itself does not support dynamic cursors, but it can be achieved through (Prepared statements + views + static cursors) methods.
A simple example:
-- Create a test table and data create table webuser (username varchar (10); insert into webuser values ('a1'), ('a2 '), ('a3 '), ('b1 '), ('b2'), ('b3'); Commit; -- create a stored procedure 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; -- Test Call dynamic_cursor ('A ');