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行记录, 然后我想每次取出一行 ...
随机推荐
- 331. Verify Preorder Serialization of a Binary Tree
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, ...
- poj3249 Test for Job ——拓扑+DP
link:http://poj.org/problem?id=3249 在拓扑排序的过程中进行状态转移,dp[i]表示从起点到 i 这个点所得到的的最大值.比如从u点到v点,dp[v]=max(dp[ ...
- android解析json包(接口)
package com.http.test; 02 03 04 import org.apache.http.HttpResponse; 05 import org.apache.http ...
- java编程之:Unsafe类
Unsafe类在jdk 源码的多个类中用到,这个类的提供了一些绕开JVM的更底层功能,基于它的实现可以提高效率.但是,它是一把双刃剑:正如它的名字所预示的那样,它是 Unsafe的,它所分配的内存需要 ...
- FileReader/FileWriter复制文件
public class Test{ /*FileReader/FileWriter读写乱码,待处理*/ public static void main(String[] args) throws I ...
- jquery获取高度错误(可以获取到宽度,但获取不到高度),及解决办法
<div class="foo"> <div style="display: none;"> 3333333 </div> ...
- jquery得到iframe src属性值的方法
这篇文章主要介绍了jquery得到iframe src属性值的方法,很简单,很实用,需要的朋友可以参考下 取得iframe src属性的的值: Html代码 <!DOCTYPE HTML> ...
- rsync-3.0.6-64
http://rsync.samba.org/ 用的是rsync-3.0.6-12.el6.x86_64 Rsync version 3.1.1 released June 22nd, 2014 Rs ...
- Linux-LNMP LAMP LNMPA
这个脚本是使用shell编写,为了快速在生产环境上部署lnmp/lamp/lnmpa(Linux.Nginx/Tengine.MySQL/MariaDB/Percona.PHP),适用于CentOS ...
- 【转】php curl 伪造IP来源的实例代码
curl发出请求的文件fake_ip.php: 代码 复制代码 代码如下: <?php $ch = curl_init(); $url = "http://localhost/targ ...