儲存過程中帶游標

2021-08-03 04:51:00 字數 1782 閱讀 6129

create procedure updatetimeproperty

@surroundingrock nvarchar(200),

@ifclassname nvarchar(200),

@prop_startstation nvarchar(200),

@prop_endstatoin nvarchar(200),

@starttime nvarchar(200),

@unittime nvarchar(200)

asbegin

declare @curstartstation nvarchar(200)

declare @curendstatoin nvarchar(200)

declare @ebs nvarchar(200)

declare getnum cursor

for(select prop_startstation,prop_endstatoin,ebs from v_itemproperty

where surroundingrock=@surroundingrock and ifcclassname=@ifclassname)

open getnum;

fetch next from getnum into @curstartstation,@curendstatoin,@ebs;

while @@fetch_status = 0

begin

if(((select dbo.f_getnum(@curstartstation) as curstartstation) > (select dbo.f_getnum(@prop_startstation) as prop_startstation)) and -----游標中的開始樁號大於引數的開始樁號

((select dbo.f_getnum(@curendstatoin) as curendstatoin)<(select dbo.f_getnum(@prop_endstatoin) as prop_endstatoin) ) and-----游標中的結束樁號要小於引數的結束樁號

((select dbo.f_getnum(@curstartstation) as curstartstation) <(select dbo.f_getnum(@prop_endstatoin) as prop_endstatoin))and-----游標中的開始樁號小於引數的結束樁號

((select dbo.f_getnum(@curendstatoin) as curendstatoin)>(select dbo.f_getnum(@prop_startstation) as prop_startstation)) -------游標中的結束樁號大於引數中的開始樁號

)update t_componentproperty

set value=@curstartstation

where t_componentproperty.ebs=@ebs and name='schedulestarttime';

update t_componentproperty

set value=@curendstatoin

where t_componentproperty.ebs=@ebs and name='scheduleendtime';

fetch next from getnum into @curstartstation,@curendstatoin,@ebs;

endclose getnum

deallocate getnum

endgo

儲存過程中的游標使用

利用儲存過程來消除資料庫中冗餘的資料 create procedure sp mytest as declare pro varchar 50 declare mm int declare wu cursor for select distinct product from mytest open ...

儲存過程中游標的使用

例如 乙個公司,按照如下規則計算加薪金額 1.公司中除了總裁 president 外,所有人都會至少增加p min的薪水 2.任何獎金 bonus 高於 600的員工都會另增加4 3.員工的佣金 commission 越高,增加越少。佣金 commission 少於 2000的另增加3 佣金 com...

儲存過程中的游標cursor

儲存過程裡的游標,其實就是結果集,然後想操作結果集中的資料,一行行讀取游標即可 首先要宣告乙個游標 delimiter create procedure changename begin declare stopflag int default 0 declare myname varchar 20...