SQL Server游標(biāo)和存儲過程共同使用的例子
作者:佚名
SQL Server游標(biāo)和存儲過程都是SQL Server中非常重要的,如果能夠一起使用,自然再好不過,下面為您舉例說明SQL Server游標(biāo)和存儲過程共同使用的的方法,供您參考。
下面為您介紹的例子共同使用了SQL Server游標(biāo)和SQL Server存儲過程,如果您SQL Server游標(biāo)和存儲過程都比較感興趣的話,不妨一看。
- If Object_ID('dbo.GetMasterGoods') Is Not Null
- Drop Proc dbo.GetMasterGoods
- Go
- Create Proc GetMasterGoods
- @MyCursor Cursor Varying Output
- With Encryption
- As
- Set @MyCursor = Cursor
- For
- Select GoodsCode,GoodsName From Master_Goods
- Open @MyCursor
- Go
- --下邊建立另外一個存儲過程,用于遍歷游標(biāo)輸出結(jié)果
- Create Proc GetAllGoodsIDAndName
- As
- Declare @GoodsCode varchar(18)
- Declare @GoodsName nvarchar(20)
- Declare @MasterGoodsCursor Cursor
- Exec GetMasterGoods @MasterGoodsCursor out
- Fetch Next From @MasterGoodsCursor
- InTo @GoodsCode,@GoodsName
- While(@@Fetch_Status = 0)
- Begin
- Begin
- Print @GoodsCode + ':' + @GoodsName
- End
- Fetch Next From @MasterGoodsCursor
- InTo @GoodsCode,@GoodsName
- End
- Close @MasterGoodsCursor
- Deallocate @MasterGoodsCursor
- Go
以上就是SQL Server游標(biāo)和存儲過程共同使用的方法。
【編輯推薦】
責(zé)任編輯:段燃
來源:
互聯(lián)網(wǎng)