delimiter $$
drop procedure if exists sp_c $$
create procedure sp_c (out oMax int)
begin
declare cur1 cursor for select eid from emp;
declare iMax,iTemp int;
declare i int;
set i=1;
open cur1;
fetch cur1 into iTemp;
set iMax=iTemp;
while i< 500 do
fetch cur1 into iTemp;
if iTemp>iMax then
set iMax=iTemp;
end if;
end while;
close cur1;
set oMax=iMax;
end$$
delimiter ;我刚学习游标的使用.这里主要有什么问题?还有.哪里有游标的例子啊?
drop procedure if exists sp_c $$
create procedure sp_c (out oMax int)
begin
declare cur1 cursor for select eid from emp;
declare iMax,iTemp int;
declare i int;
set i=1;
open cur1;
fetch cur1 into iTemp;
set iMax=iTemp;
while i< 500 do
fetch cur1 into iTemp;
if iTemp>iMax then
set iMax=iTemp;
end if;
end while;
close cur1;
set oMax=iMax;
end$$
delimiter ;我刚学习游标的使用.这里主要有什么问题?还有.哪里有游标的例子啊?
解决方案 »
- 为什么mysql那么慢啊,比ACCESS还要慢,一个最简单的查询几乎要用一分钟!
- MYSQL服务无法启动
- MySQL指定INI注册服务,无法启动服务
- 我的WEB程序访问MYSQL是不要密码的,可是MYSQL有密码?
- select distinct的sql语句如何优化
- mysql触发器问题
- VB中ADODC.Recordset.Addnew方法的使用!!?????????
- 菜鸟问题
- 添加外键爆错:Duplicate key name 求大神
- mysql community server 和mysql on windows( installer& tools)区别
- 一个SQL查询的菜鸟问题~请指教啊~~~
- 刚安装了个5.0版的mysql数据库,怎么就连接不上呢???
GO
SET ANSI_NULLS ON
GOUSE pubs
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'sp_c' AND type = 'P')
DROP PROCEDURE sp_c
GO
create procedure sp_c
(
@oMax int
)
AS
BEGIN
-- 為 CURSOR 物件提供變數, 以保存 CURSOR 物件當前行欄位值
DECLARE @nMax int
DECLARE rs_cursor CURSOR FOR
select eid from emp
OPEN rs_cursor
FETCH NEXT FROM rs_cursor INTO @nMax
WHILE @@FETCH_STATUS = 0
BEGIN
-------------在這裡面做你想要做的事情
FETCH NEXT FROM rs_cursor INTO @CP_NO
END
CLOSE rs_cursor
DEALLOCATE rs_cursor
-- 返回資料集
ReturnData:
-- 事務完成, 退出預存程序
RETURN 0
-- 錯誤處理
ErrorHandler:
GOTO ReturnData
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO