mysql之游标
游标
mysql> delimiter //
mysql> create procedure duhuo()
-> begin
-> declare ordnums cursor
-> for
-> select order_num from orders;
-> end
-> //
OPEN ordnums;
close ordnums;
mysql> delimiter //
mysql> create procedure duhuo1()
-> begin
-> declare dudu cursor
-> for
-> select order_num from orders;
-> open dudu;
-> close dudu;
-> end
-> //
mysql> delimiter //
mysql> create procedure demo0()
-> begin
-> declare tx int;
-> declare du1 cursor
-> for
-> select order_num from orders;
-> open du1;
-> fetch du1 into tx;
-> close du1;
-> end
-> //
Query OK, 0 rows affected (0.02 sec)
mysql> create procedure demo0()
-> begin
-> delcare done boolean default 0;
-> declare du int;
-> declare ordernu cursor
-> for
-> select order_num from orders;
-> declare continue handler for sqlstate '' set done = 1;
-> open ordernu;
-> repeat
-> fetch ordernu into du;
-> until done end repeat;
-> close ordernu;
-> end//
declare continue handler for sqlstate '' set done = 1;
mysql> delimiter //
mysql> create procedure liwei()
-> begin
-> declare done boolean default 0;
-> declare li int;
-> declare wei decimal(8,2);
-> declare numb cursor
-> for
-> select order_num from orders;
-> declare continue handler for sqlstate '' set done=1;
-> create table if not exists ordertotals
-> (order_num int,total decimal(8,2));
-> open numb;
-> repeat
-> fetch ordernumbers into li;
-> call ordertotals(tx,1,t);
-> insert into ordertotals(order_num, total)
-> values(li,wei);
-> until done end repeat;
-> close numd;
-> end
-> //
call liwei();
select *
from ordertotals;
+----------------+--------------+
| order_num | total |
+----------------+--------------+
| 20005 | 158.56 |
| 20006 | 25.78 |
| 20007 | 1068.00 |
+----------------+--------------+
mysql之游标的更多相关文章
- MySQL中游标使用以及读取文本数据
原文:MySQL中游标使用以及读取文本数据 前言 之前一直没有接触数据库的学习,只是本科时候修了一本数据库基本知识的课.当时只对C++感兴趣,天真的认为其它的课都没有用,数据库也是半懂不懂,胡乱就考试 ...
- MySQL存储过程 游标
MySQL存储过程 游标 如何在存储过程中使用MySQL游标来遍历SELECT语句返回的结果集 MySQL游标简介 要处理存储过程中的结果集,请使用游标.游标允许您迭代查询返回的一组行,并相应地处理 ...
- Mysql 视图 游标 触发器 存储过程 事务
Mysql 视图 触发器 存储过程 游标 游标是从数据表中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向的是首记录,利用fetch语句可以移动该指针,从而对游标中 ...
- MySql使用游标Cursor循环(While)更新数据
#要修改的变量 DECLARE var_ID VARCHAR(50) DEFAULT ''; #需要修改的数据的数量 DECLARE var_UpdateCount INT; #当前循环次数 DECL ...
- MySql 中游标,事务,终止存储过程方法总结
最近在项目开发中,有段逻辑处理,需要在网站,app,后台分别运行,这样给后期的维护带来了很大的不方便,容易遗漏app端或者后台,所以讲java代码转换成存储过程,把逻辑处理写在了mysql端,其中遇到 ...
- 用 Navicat 写mysql的游标
千言万语也比不上一个简单直接明了的小例子: CREATE PROCEDURE pro_users() begin DECLARE myid int; DECLARE no int; ); ); ); ...
- 【MySQL】游标的具体使用详解
测试表 level ; )); 再 insert 些数据 ;代码,初始化 drop procedure if exists useCursor // 建立 存储过程 create CREATE PRO ...
- MySql命令——游标
1.游标的概念 有时,需要在检索出来的行中前进或后退一行或多行.这就是使用游标的原因.游标(cursor)是一个存储在 MySql 服务器上的数据库查询,它不是一条 select 语句,而是被该语句检 ...
- mysql 简单游标
<=====================MYSQL 游标示例=====================> CREATE PROCEDURE `test`.`new_procedure` ...
随机推荐
- 今天开始应该使用 5 个JavaScript调试技巧
原文:5 Javascript debugging tips you’ll start using today 我之前使用过用 printf debugging,自此之后我用这种方法似乎总能更快地解决 ...
- 从零开始学ios开发(一):准备起航
首先介绍一下自己的背景,本人09年研究生毕业,大学就不介绍了,反正是上海的一所211大学,学的是计算机科学与技术专业,学生时代,从事过ACM,没有什么太大的成就,中国的牛人是在太多,我的水平,估计连高 ...
- Entity Framework 学习第一天
文章是作为初学者记录之用,没有学习过的同学可以借鉴一下,至于用过和高手嘛,就算了吧.仅是入门.废话不多说了,马上新建个项目,添加Entity Framework,这个词以下将用EF代替. 本文使用的I ...
- 【学习总结】iOS中NSNotification、delegate、KVO三者之间的区别与联系?
在开发ios应用的时候,我们会经常遇到一个常见的问题:在不过分耦合的前提下,controllers间怎么进行通信.在IOS应用不断的出现三种模式来实现这种通信: 1.委托delegation: 2.通 ...
- P1119: [POI2009]SLO
这题预处理稍微动动脑,其实还是个裸的置换群=-=,没什么压力. ; var n,i,j,minx,tem,now,tmin,len:longint; cursum,sum:int64; pos,num ...
- MySQL - 定时备份
创建备份目录,在这里以/root/bak/mysql为例: cd mkdir bak cd bak mkdir mysql 在/usr/sbin下touch一个sh: cd /usr/sbin tou ...
- Jquery获取选中的checkbox的值
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...
- android 开发 对图片编码,并生成gif图片
demo场景: 将2张静态的png格式图片组合生成一个gif图片,间隔500毫秒,关键类:AnimatedGifEncoder 如需要解析gif获取每帧的图片,可参考上一篇博客:<android ...
- 【Insertion Sorted List】cpp
题目: Sort a linked list using insertion sort. 代码: /** * Definition for singly-linked list. * struct L ...
- HashMap优雅的初始化方式以及引申
小记 相信很多人和笔者一样,经常会做一些数组的初始化工作,也肯定会经常用到集合类.假如我现在要初始化一个String类型的数组,可以很方便的使用如下代码: String [] strs = {&quo ...