sql 游标

Posted 亮亮1990

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 游标相关的知识,希望对你有一定的参考价值。

ALTER PROCEDURE [dbo].[xuexiao]
	
AS
BEGIN
	declare @id int
	declare @yiji nvarchar(50)
	declare @erji nvarchar(50)
	declare @sanji nvarchar(50)
	declare xuexiao_cursor cursor 
	for select id,yiji,erji,sanji from sys_school2 where areaid is null
	Open xuexiao_cursor
	fetch next from xuexiao_cursor into @id,@yiji,@erji,@sanji
    While(@@Fetch_Status = 0)
      Begin
			declare @regionid int 
			select @regionid=regionid from Sys_Regions  where layer=3 and REPLACE(name,' ','') = @sanji and provincename like (@yiji + '%') and cityname like (@erji + '%')
			update Sys_School2 set areaid=@regionid where id=@id
			--select * from sys_school2 where id=@id
             --select @regionid
		fetch next from xuexiao_cursor into @id,@yiji,@erji,@sanji
      End
Close xuexiao_cursor
Deallocate xuexiao_cursor
END

以上是关于sql 游标的主要内容,如果未能解决你的问题,请参考以下文章

SQL游标怎么用

Oracle下如何用sql创建游标

sql server 中游标详解

SQL记录-PLSQL游标

Sql中的游标是干嘛的

SQL Server游标