MySQL游标语法实例
MySQL游标语法实例
1、基本语法:
Sql代码
#定义游标
declare fetchSeqCursor cursor for select seqname, value from sys_sequence;
#使用游标
open fetchSeqCursor;
#fetch数据
fetch cursor into _seqname, _value;
#关闭游标
close fetchSeqCursor; www.2cto.com
2、单游标例子:
Sql代码
## 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; select _seqname, _value;
end if; end Loop;
close fetchSeqCursor; www.2cto.com
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; www.2cto.com
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;
MySQL游标语法实例相关推荐
- mysql游标事例_MySQL游标语法实例
1.基本语法: Sql代码 #定义游标 declare fetchSeqCursor cursor for select seqname, value from sys_sequence; #使用游标 ...
- Mysql Insert Or Update语法实例
有的时候会需要写一段insert的sql,如果主键存在,则update:如果主键不存在,则insert.Mysql中提供了这样的用法:ON DUPLICATE KEY UPDATE.下面就看看它是如何 ...
- mysql 删除字段语法_mysql增添、修改、删除字段语法实例
mysql增添.修改.删除字段语法实例 mysql 添加.修改.删除字段语法实例 sql alert 添加.修改.删除字段语法实例 alter table 的语法如下: alter table &qu ...
- mysql shutdown 命令_Mysql 5.7.9 shutdown 语法实例详解
mysql-5.7.9 终于提供shutdown 语法啦: 之前如果想关闭一个mysql数据库可以通过kill 命令.mysqladmin shutdown .service mysqld stop ...
- mysql游标循环的使用_实例详解mysql游标循环的使用
这篇文章主要介绍了mysql游标循环的使用,有一定的参考价值,感兴趣的朋友可以参考一下,希望对你有所帮助!CREATE PROCEDURE `test`.`new_procedure` ()BEGIN ...
- mysql 游标 navigate_MySQL游标的概念介绍和游标的使用讲解
一.MySQL游标的概念 1.游标介绍 MySQL的游标(cursor)是一个重要的概念,通过查找资料与自己的理解,主要得出以下几点关于自己的理解. 有数据缓冲的思想:游标的设计是一种数据缓冲区的思想 ...
- mysql游标 原理解说_mysql存储过程之游标(DECLARE)原理与用法详解
本文实例讲述了mysql存储过程之游标(DECLARE)原理与用法.分享给大家供大家参考,具体如下: 我们在处理存储过程中的结果集时,可以使用游标,因为游标允许我们迭代查询返回的一组行,并相应地处理每 ...
- mysql 创建游标报错,MySQL游标概念与用法详解
本文实例讲述了mysql游标概念与用法.分享给大家供大家参考,具体如下: 1.游标的概念(cursor) 一条sql,对应n条资源,取出资源的接口,就是游标,沿着游标,可以一次取出1行.如果开发过安卓 ...
- mysql游标_MySQL游标概念与用法详解
本文实例讲述了MySQL游标概念与用法.分享给大家供大家参考,具体如下: 1.游标的概念(Cursor) 一条sql,对应N条资源,取出资源的接口,就是游标,沿着游标,可以一次取出1行.如果开发过安卓 ...
最新文章
- 中国开发者新福利:大模型API接口出炉,让普通用户玩转内容生成
- 2020公文格式模板及范文_四六级考试答题顺序推荐 2020四级作文预测 四级作文范文模板...
- 来活儿了!赶紧检查下代码里有没有脏话...
- .Net微信开发之通过UnionID机制,解决用户在不同公众号,或在公众号、移动应用之间帐号统一问题...
- Pixhawk原生固件PX4之串口添加读取传感器实现
- PHP 入门 - 10.应用技术
- android媒体播放框架,Android 使用超简单的多媒体播放器JiaoZiVideoPlayer
- Linux把文件移动到容器外,Docker容器与主机之间拷贝文件的方法
- 说说说vue.js中的组
- Cinemachine教程 | Unity中如何制作路径动画?
- Java二叉搜索树转循环链表,关于java:二叉搜索树转换为单向链表interview1712
- java简单单向链表_用java简单的实现单链表的基本操作
- Nginx静态资源POST请求返回405状态
- 天正电气lisp是什么文件_LSP文件扩展名 - 什么是.lsp以及如何打开? - ReviverSoft...
- 每天一kernel:正太概率图
- border和boder-radius
- JAVA后台开发提升注解篇 @Deprecated
- git cheatsheet
- 计算机系统基础期末复习--袁春风详细版
- android 微信分身开发,【技巧】2021安卓手机微信分身方法