儲存過程建立游標

2021-08-25 16:31:41 字數 1282 閱讀 3450

create procedure proc_syn_data

asbegin

set nocount on;

declare @id varchar(50);

declare @name varchar(100);

declare @keyid varchar(50);

declare @updatetime varchar(50);

-- 1.宣告游標

declare cur_monthid cursor for

select schoolid,sname from dbo.gk_schoolinfo

declare cur_monthid2 cursor for

select rareasid,updatetime from dbo.gk_resiareasinfo

-- 2.開啟游標

open cur_monthid

open cur_monthid2

-- 3.從乙個游標中查詢資訊,實現自己的資料處理。

fetch cur_monthid into @id,@name

fetch cur_monthid2 into @keyid,@updatetime

while @@fetch_status=0

begin

select @id=schoolid,@name=sname from dbo.gk_schoolinfo

select @keyid=rareasid,@updatetime=updatetime from dbo.gk_resiareasinfo

fetch next from cur_monthid into @id,@name

fetch next from cur_monthid2 into @keyid,@updatetime

print('---'+@id+'---'+@name+'|---|'+@keyid+'****'+@updatetime)

end;

-- 4.關閉游標

close cur_monthid;

close cur_monthid2;

-- 5.釋放游標

deallocate cur_monthid;

deallocate cur_monthid2;

end;

exec proc_syn_data;

@@fetch_status

返回值 說明

0fetch 語句成功。

-1fetch 語句失敗或行不在結果集中。

-2提取的行不存在。

oracle儲存過程,游標

oracle儲存過程,游標 2010 07 07 13 01 create or replace procedure p tb task log is 功能 插入任務到任務日誌表 v task start date date v task end date date v sql code numbe...

儲存過程與游標

有以下4種 1.使用show procedure status命令檢視儲存過程的定義 2.檢視某個資料庫中所有儲存過程名 select name from mysql.proc where db yourdb and type procedure 使用mysql命令 show create proc...

mysql 游標 儲存過程

1.首先需要注意的是mysql中游標必須要建立在儲存過程中 2.直接上sql 查詢當天資料 select in flow out flow from water meter data where 1 1 and date sys read time curdate 1 order by in flo...