首页 数据库 mysql教程 MySQL游标语法实例

MySQL游标语法实例

Jun 07, 2016 pm 03:14 PM
linux mysql 实例 游标 社区 语法 进入

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 1、基本语法: Sql代码 #定义游标 declare fetchSeqCursor cursor for select seqname, value from sys_sequence; #使用游标 open fetchSeqCursor; #fetch数据 fetch cursor into _seqname, _value;

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  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

  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;

MySQL游标语法实例

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Android TV Box 获得非官方 Ubuntu 24.04 升级 Android TV Box 获得非官方 Ubuntu 24.04 升级 Sep 05, 2024 am 06:33 AM

Android TV Box 获得非官方 Ubuntu 24.04 升级

deepseek网页版入口 deepseek官网入口 deepseek网页版入口 deepseek官网入口 Feb 19, 2025 pm 04:54 PM

deepseek网页版入口 deepseek官网入口

deepseek怎么安装 deepseek怎么安装 Feb 19, 2025 pm 05:48 PM

deepseek怎么安装

如何修复 MySQL 8.4 上的 mysql_native_password 未加载错误 如何修复 MySQL 8.4 上的 mysql_native_password 未加载错误 Dec 09, 2024 am 11:42 AM

如何修复 MySQL 8.4 上的 mysql_native_password 未加载错误

BitPie比特派钱包app下载地址 BitPie比特派钱包app下载地址 Sep 10, 2024 pm 12:10 PM

BitPie比特派钱包app下载地址

BITGet官方网站安装(2025新手指南) BITGet官方网站安装(2025新手指南) Feb 21, 2025 pm 08:42 PM

BITGet官方网站安装(2025新手指南)

Zabbix 3.4 源码编译安装 Zabbix 3.4 源码编译安装 Sep 04, 2024 am 07:32 AM

Zabbix 3.4 源码编译安装

详解:Shell脚本变量判断参数命令 详解:Shell脚本变量判断参数命令 Sep 02, 2024 pm 03:25 PM

详解:Shell脚本变量判断参数命令

See all articles