MySQL游标

While循环

-- MySQL游标只能用于存储过程和函数

-- 使用过程 声明、打开游标、使用游标、关闭游标

-- 如果未明确关闭游标,END时会自动关闭

-- https://dev.mysql.com/doc/refman/8.0/en/error-handling.html

drop PROCEDURE if exists process_user;

create procedure process_user()

begin

-- Declare local variables

declare done boolean default true;

declare user_id int;

declare user_info varchar(50);

-- Declare the cursor

declare cursor_user cursor for select id, user_name from sys_user;

-- Declare continue handler

declare continue handler for sqlstate '02000' set done=false;

-- Create a table to store the results;

create table if not exists process_user_result(user_id int, user_name varchar(50));

-- Open the cursor

open cursor_user;

-- Repeat through all rows

repeat

fetch cursor_user into user_id, user_info;

if done then

insert into process_user_result(user_id, user_name)

values(user_id, user_info);

end if;

until (not done) end repeat;

-- Close the cursor

close cursor_user;

end;

call process_user();

Repeat循环

drop PROCEDURE if exists process_user;

create procedure process_user()

begin

-- Declare local variables

declare done boolean default true;

declare user_id int;

declare user_info varchar(50);

-- Declare the cursor

declare cursor_user cursor for select id, user_name from sys_user;

-- Declare continue handler

declare continue handler for not found set done=false;

-- Create a table to store the results;

create table if not exists process_user_result(user_id int, user_name varchar(50));

-- Open the cursor

open cursor_user;

-- Loop through all rows

fetch cursor_user into user_id, user_info;

while done do

insert into process_user_result(user_id, user_name)

values(user_id, user_info);

fetch cursor_user into user_id, user_info;

end while;

-- Close the cursor

close cursor_user;

end;

call process_user();

Loop循环

drop PROCEDURE if exists process_user;

create procedure process_user()

begin

-- Declare local variables

declare done boolean default true;

declare user_id int;

declare user_info varchar(50);

-- Declare the cursor

declare cursor_user cursor for select id, user_name from sys_user;

-- Declare continue handler

declare continue handler for not found set done=false;

-- Create a table to store the results;

create table if not exists process_user_result(user_id int, user_name varchar(50));

-- Open the cursor

open cursor_user;

-- Loop through all rows

read_loop:loop

fetch cursor_user into user_id, user_info;

if not done then

leave read_loop;

end if;

insert into process_user_result(user_id, user_name) values(user_id, user_info);

end loop;

-- Close the cursor

close cursor_user;

end;

call process_user();

java 用mysql游标_MySQL游标相关推荐

  1. 什么是mysql的游标_MySQL游标概念是什么 MySQL游标概念与用法介绍

    本篇文章小编给大家分享一下MySQL游标概念与用法介绍,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看. 1.游标的概念(Cursor) 一条sql,对应N条资源,取出资源的接 ...

  2. mysql游标_MySQL游标概念与用法详解

    本文实例讲述了MySQL游标概念与用法.分享给大家供大家参考,具体如下: 1.游标的概念(Cursor) 一条sql,对应N条资源,取出资源的接口,就是游标,沿着游标,可以一次取出1行.如果开发过安卓 ...

  3. mysql while 游标_mysql 游标 loop while 的使用

    项目需求:对表进行重新构建,这个用java的缺点是数据的传送以及遍历的话会消耗更多的资源,因此使用mysql的存储过程进行构建. 具体要求:跳过原本设置的假期和课程本身的假期对数据进行重排. 1.游标 ...

  4. mysql游标_MySQL 游标的使用

    MySQL 游标 游标的特性 不敏感:数据库可以选择不复制结果集 只读 不滚动:游标只能向一方向前进,并且不可以跳过任何一行数据 游标的优点 游标是针对行操作的,对从数据库中 select 查询得到的 ...

  5. mysql c 游标_mysql游标示例 mysql游标简易教程

    从mysql V5.5开始,进行了一次大的改变,就是将InnoDB作为默认的存储引擎.InnoDB支持事务,而且拥有相关的RDBMS特性:ACID事务支持,数据完整性(支持外键),灾难恢复能力等等. ...

  6. java 备份 mysql 日志_MySQL 数据备份与还原

    点击上方"Java知音",选择"置顶公众号" 技术文章第一时间送达! 作者:逆心 链接:https://www.cnblogs.com/kissdodog 公众 ...

  7. java毫秒 mysql秒_MySQL和Java时间毫秒之间的转换问题的总结

    在做关于依时间查询用户认证的业务,因为在MySQL中,time字段使用的是bigint类型,所以存在其中都是毫秒数.当需要从数据库中取出 最近几天在做关于依时间查询用户认证的业务,因为在MySQL中, ...

  8. java读取mysql配置文件_MySql主从复制,从原理到实践

    推荐阅读: 成功斩获头条offer,Java程序员心得分享给你春招助力 摘要 本文将从MySql主从复制的原理出发,详细介绍MySql在Docker环境下的主从复制搭建,以一个主实例和一个从实例实现主 ...

  9. Java创建MySQL句柄_MySQL创建用户(CREATE USER)

    在对 MySQL 的日常管理和实际操作中,为了避免用户恶意冒名使用 root 账号控制数据库,通常需要创建一系列具备适当权限的账号,应该尽可能地不用或少用 root 账号登录系统,以此来确保数据的安全 ...

  10. java 设置mysql 密码_Mysql修改设置root密码的命令及方法

    Mysql数据库是PHP网站开发必不可少的组合,通常PHP连接 Mysql都是通过root用户名和密码连接,Mysql在安装时root初始默认密码为空,在安装使用PHP开源系统时,都需要填写连接Mys ...

最新文章

  1. python学习音频-机器学习利用Python进行音频数据增强
  2. 分布式电子邮件系统设计--转载
  3. ubuntu c++ 实现自动回车键功能_从X86到ARM,实现C和C++语言90% Code自动迁移
  4. 2021牛客暑期多校训练营6 Hopping Rabbit 扫描线 + 矩形 + 细节
  5. 计算机仿真在机械应用,浅谈计算机仿真在机械的应用.doc
  6. React之组件与模块
  7. puppet连载15:搭建zabbix服务端、客户端
  8. 精品|从零开始-基于FPGA 的软核处理器设计实现
  9. 计算机表格中格式隐藏了怎么办,Excel表格“隐藏”和“取消隐藏”工作表、行、列 -电脑资料...
  10. python世界杯问题
  11. solver参数详解
  12. blastn 输出结果每列啥意思_本地blast的详细用法
  13. 学校的计算机是作文,我在学校作文
  14. 无法解析服务器的dns地址
  15. java hypot_java – 为什么hypot()函数这么慢?
  16. 固态硬盘读写速度快的原理是什么?
  17. Linux从入门到入狱-01
  18. 【渝粤教育】电大中专计算机职业素养 (14)作业 题库
  19. Java版吃豆游戏及源码
  20. 基于TI-RTOS的CC2650DK开发(14)---邮箱

热门文章

  1. 用ping IP的方法测试网卡
  2. 图像去雾之何凯明暗通道先验去雾算法原理及c++代码实现
  3. OpenCV源码解析之动态内存管理CvMemStorage与CvSeq
  4. bash shell set 命令
  5. linux远程拷贝快捷键远程,linux命令scp远程拷贝
  6. C++ STL sort 函数的用法(自定义排序函数)
  7. C++ string构造函数和析构函数
  8. matlab 数学 应用论文,MATLAB在高等数学课程中的应用(图文)
  9. Docker 之MySQL 重启,提示Error response from daemon: driver failed programming external connectivity on **
  10. linux vim -b详解,linux vim