MySQL PLSQL Demo - 004.模拟动态游标
时间:2021-07-01 10:21:17
帮助过:3人阅读
procedure if exists p_simulate_dynamic_cursor;
create procedure p_simulate_dynamic_cursor()
begin
declare v_sql
varchar(
4000);
declare v_field
varchar(
4000);
declare v_result
varchar(
4000)
default ‘‘;
declare cur_temp
cursor for select v.
* from view_temp_20150701 v;
declare continue handler
for not found
set v_field
= null;
set v_sql
= ‘create view view_temp_20150701 as select t.id from t_user t‘;
set @v_sql = v_sql;
prepare statement
from @v_sql;
execute statement;
deallocate prepare statement;
open cur_temp;
fetch cur_temp
into v_field;
while (v_field
is not null) do
set v_result
= concat(v_result, v_field,
‘,‘);
fetch cur_temp
into v_field;
end while;
close cur_temp;
select v_result;
drop view if exists view_temp_20150701;
end;
call p_simulate_dynamic_cursor();
MySQL PLSQL Demo - 004.模拟动态游标
标签: