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` ...
随机推荐
- Knockout.Js学习目录
1.Knockout.Js(简介) 2.Knockout.Js(监控属性Observables) 3.Knockout.Js(属性绑定) 4.Knockout.Js(事件绑定) 5.Knockout. ...
- [转]ubuntu 下minicom超级终端的使用方法
[转]ubuntu 下minicom超级终端的使用方法 http://blog.chinaunix.net/uid-25909619-id-3184639.html 系统环境: Ubuntu 11.0 ...
- 微信支付.NET版开发总结(JS API),好多坑,适当精简。
前2天,做一个手机网页的微信支付的项目,费了好些周折,记录一下.接下来,按照开发步骤,细数一下,我遇到的那些坑. [坑1]官方邮件中下载的demo只有PHP版本,其他版本没有给链接.可能让人误以为只有 ...
- opencv颜色识别代码分享
android 平台 opencv 实现颜色识别代码:http://www.eyesourcecode.com/thread-40682-1-1.htmlopencv的颜色识别简单实现的代码:http ...
- Mac下的常用Shell命令
今天介绍一下在Mac的终端中一些常用的Shell命令: 1.查看当前工作目录的完整路径 pwd (pwd的原意是:print work directiory,而不是密码password的意思,呵呵) ...
- Why Every Professional Should Consider Blogging
转自http://www.pixelstech.net/article/1327829407-Why-Every-Professional-Should-Consider-Blogging ften ...
- JavaScript 异常
转载自:http://www.cnblogs.com/aqbyygyyga/archive/2011/10/29/2228824.html(排版格式修改了一下) 一.错误处理的重要性 以前,javas ...
- ptype_base和ptype_all学习笔记
"linux-2.6.32/include/linux/netdevice.h" struct packet_type { __be16 type; /* This is real ...
- 【BZOJ】【3991】【SDOI2015】寻宝游戏
dfs序 我哭啊……这题在考试的时候(我不是山东的,CH大法吼)没想出来……只写了50分的暴力QAQ 而且苦逼的写的比正解还长……我骗点分容易吗QAQ 骗分做法: 1.$n,m\leq 1000$: ...
- 【BZOJ】【1020】【SHOI2008】安全的航线flight
计算几何/二分/迭代/搜索+剪枝 写三个tag可能是因为从哪个方向来理解都可以吧…… 我完全不会计算几何所以抄了ydc的代码 题解:http://ydcydcy1.blog.163.com/blog/ ...