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` ...
随机推荐
- hdu 2645 find the nearest station
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2645 find the nearest station Description Since dande ...
- meteor 实现 微信分享
Template.hello.events({ 'click button': function () { // increment the counter when button is clicke ...
- OC中类的扩展介绍
对OC类的扩展总结如下: 共有4个: 1.子类 subClass 作用:可以使用类的继承来增添父类的变量和方法. 写法:在.h文件中 @interface Student : Person 2.分类 ...
- Extjs-工具条和菜单 Ext.menu和Ext.Toolbar
转载自:http://blog.csdn.net/itlwc/article/details/7878002 1.创建一个简单工具条效果图 <script type="text/jav ...
- SQL Server数据库学习笔记-三大范式
第一范式(First Normal Form,简称1NF):数据库表中的字段都是单一属性的,不可再分.这个单一属性由基本类型构成,包括整型.实数.字符型.逻辑型.日期型等.要求一个属性只包含一个值,多 ...
- 四、VMware Tools 安装 与 问题
解决VMware Tools无法安装的问题 虚拟机上装win2kgho版的系统,安装VMware Tools时,遇到“VMware Tools installation cannot be start ...
- C++中的set和java的hashset有何区别?
以前对C++的STL容器烂熟于心,两年没碰过C++了,现在已经很生疏了.工作原因转战java,对java的容器不甚了解,特别是每看到一种容器,不由自主地拿起和C++对比.C++中的set和java的h ...
- 使用Java Service Wrapper在Linux下配置Tomcat应用
前言 Java Service Wrapper是Tanuki Software的一个产品,可以将Java应用注册成Windows或Linux服务,使其可以随系统开机启动,同时可以监控Java应用的状态 ...
- 【BZOJ】【1150】【CTSC2007】数据备份Backup
堆/贪心 一共N-1个元素……用堆维护最大值,取了第x个元素以后,插入v[x-1]+v[x+1]-v[x]这个元素,如果再取这个新元素就表示不取x,而取x-1和x+1……大概就是这种“带反悔”的思路吧 ...
- 0910 noip模拟
教师节快乐: T1:勇士闯魔塔,是一道很裸的莫队题目,但在老师的催促下,出题人@syq同学修改了第一题,使之成了一道送分题,全暴力水过: T2:第二题是一道预处理+分组背包,考试中,忘了分组背包怎么敲 ...