Mysql游标的简明写法
-- cursor 游标
/*
declare 声明; declare 游标名 cursor for select_statement;
open 找开; open 游标名
fetch 取值; fetch 游标名 into var1,var2,var3[,...]
close 关闭; close 游标名;
*/
create procedure p12()
begin
declare row_gid int;
declare row_num int;
declare row_name varchar(20);
declare getgoods cursor for select gid,num,name from goods;
open getgoods;
fetch getgoods into row_gid,row_num,row_name;
select row_num,row_name;
close getgoods;
end;
create procedure p13()
begin
declare cnt int default 0;
declare i int default 0 ;
declare row_gid int;
declare row_num int;
declare row_name varchar(20);
declare getgoods cursor for select gid,num,name from goods;
select count(*) into cnt from goods;
open getgoods;
repeat
set i := i+1;
fetch getgoods into row_gid,row_num,row_name;
select row_num,row_name;
until i>=cnt end repeat;
close getgoods;
end;
--利用标误码来结束循环
--在mysql cursor中,可以把declare continue handler来操作1个越界标识
/*
declare continue handler for not found 语句;
*/
create procedure p14()
begin
declare row_gid int;
declare row_num int;
declare row_name varchar(20);
declare flag int default 1; --标识
declare getgoods cursor for select gid,num,name from goods;
declare continue handler for NOT FOUND set flag := 0;
open getgoods;
repeat
if flag!=0 then
fetch getgoods into row_gid,row_num,row_name;
select row_num,row_name;
end if;
until flag=0 end repeat;
close getgoods;
end;
Mysql游标的简明写法的更多相关文章
- SqlServer和MySQL游标学习
一 sqlserver游标使用 /*** 游标的使用 讲了这个多游标的优点,现在我们就亲自来揭开游标的神秘的面纱. 使用游标的顺序: 声名游标.打开游标.读取数据.关闭游标.删除游标. 1.3.1 ...
- MySQL游标操作指南
本篇文章是对MySQL游标的具体使用进行了详细的分析介绍,需要的朋友参考下 测试表 level 代码如下: create table test.level (name varchar(20)); ...
- php中mysql语句的基本写法
php中mysql语句的基本写法 php作为一门后台语言必须要与mysql数据库打交道,做到将内容存储到数据库以及数据库数据读写的操作,那么下面就来说下最近学习的一些东西: 在具体将之前先说一下编码的 ...
- 个人笔记mysql游标
经过测试,mysql游标是无法读取自定义函数计算的结构,mysql自带的函数计算值是可以读取的.
- MySQL游标的简单实践
Q:为什么要使用游标? A: 在存储过程(或函数)中,如果某条select语句返回的结果集中只有1行,可以使用select into语句(上几篇博客有介绍到用法)来得到该行进行处理:如果结果集中有多行 ...
- mysql 游标 demo
一.MySQL游标的概念 1.游标介绍 MySQL的游标(cursor)是一个重要的概念,通过查找资料与自己的理解,主要得出以下几点关于自己的理解. 有数据缓冲的思想:游标的设计是一种数据缓冲区的思想 ...
- springboot成神之——springboot+mybatis+mysql搭建项目简明demo
springboot+mybatis+mysql搭建项目简明demo 项目所需目录结构 pom.xml文件配置 application.properties文件配置 MyApplication.jav ...
- [转]MySQL游标的使用
转自:http://www.cnblogs.com/sk-net/archive/2011/09/07/2170224.html 以下的文章主要介绍的是MySQL游标的使用笔记,其可以用在存储过程的S ...
- Mysql 游标初识
MySql 游标初识 认识 游标(cursor), 按字面意思可理解为, 游动的标识, 或者叫做"光标", 这样更容易理解. 就好比现有一张表存储了n行记录, 然后我想每次取出一行 ...
随机推荐
- poj 1260 dp
Description In Pearlania everybody is fond of pearls. One company, called The Royal Pearl, produces ...
- HDU 2083 简易版之最短距离 --- 水题
HDU 2083 简易版之最短距离 /* HDU 2083 简易版之最短距离 */ #include <cstdio> #include <algorithm> using n ...
- hdu3072 强连通+最小树形图
题意:有一个人他要把一个消息通知到所有人,已知一些通知关系:A 能通知 B,需要花费 v,而又知道,如果某一个小团体,其中的成员相互都能直接或间接通知到,那么他们之间的消息传递是不需要花费的,现在问这 ...
- 状态压缩dp 入门
1.有一张n*m (n<=m)的棋盘,在上面放n个中国象棋里的车,使得任意两个车不能相互攻击,总共有多少种不同的方案. 2.有一张n*m (n<=m)的棋盘,其中有些格子里面不能放,在上面 ...
- Linux应用程序的地址布局
转载自:http://blog.csdn.net/embedded_hunter http://www.360doc.com/content/12/0405/00/1671317_200882538. ...
- java的nio之:java的nio系列教程之buffer的概念
一:java的nio的buffer==>Java NIO中的Buffer用于和NIO通道Channel进行交互.==>数据是从通道channel读入缓冲区buffer,从缓冲区buffer ...
- T4 Templates
T4 Templates and the Entity Framework https://msdn.microsoft.com/en-us/data/gg558520.aspx EF Designe ...
- 让图片完全显示出来,应对overflow,以及在背景中完全显示出来
1.应对overflow <script type="text/javascript"> $('.foo img').css('width','100%');//修正, ...
- CentOS6.4-RMAN定时任务备份 on 11GR2
1.rman备份脚本位置: /home/oracle ./scripts/ ./bin -----存放rman脚本 ./log ...
- Floating Action Button(漂浮按钮)
参考:http://blog.csdn.net/pengkv/article/details/46427891 效果图: 步骤一: 在build.gradle添加以下代码,导入包 dependenci ...