MySQL游标语法实例_MySQL

php中文网
发布: 2016-06-01 13:39:11
原创
1273人浏览过

bitsCN.com


mysql游标语法实例

 

1、基本语法: 

Sql代码  

#定义游标  

declare fetchSeqCursor cursor for select seqname, value from sys_sequence;  

#使用游标  

open fetchSeqCursor;  

#fetch数据  

fetch cursor into _seqname, _value;  

#关闭游标  

close fetchSeqCursor;  

2、单游标例子: 

Sql代码  

## define the flag for loop judgement  

declare fetchSeqOk boolean;   

## define the varient for store the data  

动态WEB网站中的PHP和MySQL:直观的QuickPro指南第2版
动态WEB网站中的PHP和MySQL:直观的QuickPro指南第2版

动态WEB网站中的PHP和MySQL详细反映实际程序的需求,仔细地探讨外部数据的验证(例如信用卡卡号的格式)、用户登录以及如何使用模板建立网页的标准外观。动态WEB网站中的PHP和MySQL的内容不仅仅是这些。书中还提到如何串联JavaScript与PHP让用户操作时更快、更方便。还有正确处理用户输入错误的方法,让网站看起来更专业。另外还引入大量来自PEAR外挂函数库的强大功能,对常用的、强大的包

动态WEB网站中的PHP和MySQL:直观的QuickPro指南第2版 508
查看详情 动态WEB网站中的PHP和MySQL:直观的QuickPro指南第2版

declare _seqname varchar(50);   

declare _value bigint(20);  

## define the cursor  

declare fetchSeqCursor cursor for select seqname, value from sys_sequence;  

## define the continue handler for not found flag  

declare continue handler for NOT FOUND set fetchSeqOk = true;   

set fetchSeqOk = false;  

  

open fetchSeqCursor;  

fetchSeqLoop:Loop  

if fetchSeqOk then  

leave fetchSeqLoop;  

else  

fetch cursor into _seqname, _value;  

  

select _seqname, _value;  

end if;  

  

end Loop;  

close fetchSeqCursor;  

3、嵌套的游标循环 

Java代码  

## define the flag for loop judgement  

declare fetchSeqOk boolean;   

## define the varient for store the data  

declare _seqname varchar(50);   

declare _value bigint(20);  

## define the cursor  

declare fetchSeqCursor cursor for select seqname, value from sys_sequence;  

## define the continue handler for not found flag  

declare continue handler for NOT FOUND set fetchSeqOk = true;   

set fetchSeqOk = false;  

open fetchSeqCursor;  

fetchSeqLoop:Loop  

if fetchSeqOk then  

leave fetchSeqLoop;  

else  

fetch cursor into _seqname, _value;   

  

#嵌套的游标循环  

begin  

  

declare fetchSeqOk boolean default 'inner';  

## define the cursor  

declare cursor2 cursor for select .... from ...;  

## define the continue handler for not   

declare continue handler for NOT FOUND set fetchSeqOk = true;   

set fetchSeqOk = false;   

open cursor2;  

fetchloop2 loop  

if fetchSeqOk then  

else  

  

end if;      

  

end loop;  

close cursor2;  

end;  

#嵌套的游标循环结束  

  

end if;  

  

end Loop;  

close fetchSeqCursor; 

 

bitsCN.com
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号