mysql游标
来源:互联网 发布:vr家装软件 编辑:程序博客网 时间:2024/05/16 18:30
说明:mysql游标只能用于存储过程中。
创建存储过程:
create procedure processorders()
begin
declare done boolean default 0;
declare o int;
declare t decimal(8,2);
--定义游标
declare ordernumbers cursor for select order_num from orders;
--declare continue handler
declare continue handler for sqlstate '02000' set done = 1;
create table if not exists ordertotals
(order_num int,total decimal(8,2));
--打开游标
open ordernumbers;
--循环所有行
REPEAT
FETCH ordernumbers into o;
call ordertotal(o,1,t);
insert into ordertotals(order_num,total) values(o,t);
--结束循环
until done end REPEAT;
--关闭游标
close ordernumbers;
end;
调用存储过程:
call processorders();
select * from ordertotals
- Mysql 游标
- mysql 游标
- MySQL游标
- mysql 游标
- MySQL游标
- mysql游标
- mySQL游标
- mysql游标
- MySQL游标
- mysql游标
- MySQL游标
- MYSQL游标
- MySQL游标
- Mysql游标
- MySQL游标
- mysql 游标
- MySQL游标
- mysql--游标
- 如何获取当前数据库名称及在存储过程中临时设置数据库兼容级别
- iOS多线程编程之NSThread的使用
- 负载均衡,会话保持,session同步
- 系统激活博客
- Launcher源码初探 转载
- mysql游标
- qt
- android2.3.5中阿拉伯文字符显示顺序不是从右至左显示
- 如何使用sublime编辑器运行python程序
- 安装Linux-Mint15 后的配置和操作
- DB2 查询前几行记录
- Leetcode:Length of Last Word
- Nginx+Memcached+Tomcat集群配置实践(Sticky Session)
- 【经验分享】---程序员的学习和积累