游标的使用
SET NOCOUNT ON
DECLARE @startip bigint
declare @addr nvarchar(50)
DECLARE @endip bigint
declare @detailaddr varchar(100)
declare @countnumber int
declare @cid int
set @countnumber=0
DECLARE publish_cursor CURSOR FOR
SELECT cast(rtrim(startip) as bigint),cast(rtrim(endip) as bigint),rtrim(addr),rtrim(detailaddr),id FROM t_ip
OPEN publish_cursor
FETCH NEXT FROM publish_cursor
INTO @startip,@endip,@addr,@detailaddr,@cid
WHILE @@FETCH_STATUS = 0
BEGIN
print @cid
--修改记录
update t_ip set ip1=@startip,ip2=@endip,addr1=@addr,addr2=@detailaddr where id=@cid
--修改结束
FETCH NEXT FROM publish_cursor into @startip,@endip,@addr,@detailaddr,@cid
END
CLOSE publish_cursor
DEALLOCATE publish_cursor
GO
DECLARE @startip bigint
declare @addr nvarchar(50)
DECLARE @endip bigint
declare @detailaddr varchar(100)
declare @countnumber int
declare @cid int
set @countnumber=0
DECLARE publish_cursor CURSOR FOR
SELECT cast(rtrim(startip) as bigint),cast(rtrim(endip) as bigint),rtrim(addr),rtrim(detailaddr),id FROM t_ip
OPEN publish_cursor
FETCH NEXT FROM publish_cursor
INTO @startip,@endip,@addr,@detailaddr,@cid
WHILE @@FETCH_STATUS = 0
BEGIN
print @cid
--修改记录
update t_ip set ip1=@startip,ip2=@endip,addr1=@addr,addr2=@detailaddr where id=@cid
--修改结束
FETCH NEXT FROM publish_cursor into @startip,@endip,@addr,@detailaddr,@cid
END
CLOSE publish_cursor
DEALLOCATE publish_cursor
GO
用来实现存储过程中对 select数据集的 读取