delimiter //
create procedure p6()
begin
declare row_id int;
declare row_username varchar(30);
declare row_details varchar(30);
declare you int default 1;
declare getusers cursor for select id ,username,details from tb_user;
declare continue handler for NOT FOUND set you:=0;
open getusers;
fetch getusers into row_id,row_username,row_details;
repeat
select row_id,row_username,row_details;
fetch getusers into row_id,row_username,row_details;
until you=0 end repeat;
close getusers;
end;
//
create procedure p6()
begin
declare row_id int;
declare row_username varchar(30);
declare row_details varchar(30);
declare you int default 1;
declare getusers cursor for select id ,username,details from tb_user;
declare continue handler for NOT FOUND set you:=0;
open getusers;
fetch getusers into row_id,row_username,row_details;
repeat
select row_id,row_username,row_details;
fetch getusers into row_id,row_username,row_details;
until you=0 end repeat;
close getusers;
end;
//
本文介绍了一个使用存储过程和游标从数据库表中获取并处理数据的示例。该示例展示了如何声明和打开游标,遍历查询结果,并在完成数据处理后关闭游标。对于理解数据库游标的工作原理及其在存储过程中的应用具有参考价值。

2404

被折叠的 条评论
为什么被折叠?



