(2.14)Mysql之SQL基础——游标

(2.14)Mysql之SQL基础——游标

关键词:Mysql游标

复制代码
-- (1)定义游标
declare cur_name cursor for
select * from table_name where condition;

-- (2)打开游标
open cur_name;

-- (3)使用游标
fetch cur_name.column_name into 变量;  -- 取下一行

-- (4)关闭游标
close cur_name;

-- (5)演示

delimiter //
create procedure sp_test3(out result text)
begin
declare flag bit default 0;
declare temp varchar(30);
declare cur cursor for select b_name from bm;
declare continue handler for not found set flag = 1;
open cur;
while flag!=1 do
fetch cur into temp;
if flag!=1 then
set result = concat_ws(',',result,temp);
end if;
end while;
close cur;
end //

 

复制代码

 

posted @   郭大侠1  阅读(168)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示