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行记录, 然后我想每次取出一行 ...
随机推荐
- Codeforces Round #366 (Div. 2) C 模拟queue
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- No module named 'pkg_resources' 解决方法
不知什么原因pip3突然不好使了....下午apt-get install && pip3 install 了好多东西,具体什么原因也找不出个所以然. 执行pip3报错: Traceb ...
- Apache运行模式
Apache 2.X 支持插入式并行处理模块,称为多路处理模块(MPM: Multi-Processing Modules).在编译apache时必须选择也只能选择一个MPM,对类UNIX系统,有几个 ...
- Codeforces378 D Kostya the Sculptor(贪心)(逻辑)
Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- POJ3308 Paratroopers(网络流)(最小割)
Paratroopers Time Limit: 1000MS Memory Limit: 655 ...
- hihoCoder#1014 Trie树 (前缀树)
题目大意:给一本有n个单词的词典,有m次询问,每次询问的是该词典中有多少个单词有共同的某个前缀. 题目分析:在添加单词建立trie的时候,每经过一个节点就意味着该节点和它的各级祖先节点是某个单词的前缀 ...
- 解决Ubuntu下vbox的(rc=-1908)
在Ubuntu下用虚拟机VBOX的时候总是遇到 Kernel driver not installed (rc=-1908) The VirtualBox Linux kernel driver (v ...
- 26 个 jQuery使用技巧
1. 禁用右键点击(Disable right-click) $(document).ready(function(){ $(document).bind("contextmenu" ...
- bootstrap 固定底部导航自适应
在使用bootstrap 底部导航的时候遇到了一个问题 -- 当我的内容超过一屏的时候,底部的部分内容会被固定的导航内容遮盖 自己写了一个JS脚本,解决自适应的问题 <nav class=&qu ...
- faster rcnn test demo ---repaired for video input and save the image, label, score et al. into .mat format
faster rcnn test demo ---repaired for video input and save the image, label, score et al. into .mat ...