sql server 2005中关于游标的问题?

来源:百度知道 编辑:UC知道 时间:2024/05/16 09:51:30
declare au_cursor cursor scroll for
select * from authors
/*打开该游标*/
open au_cursors
----定义变量,存放游标中读取的值
declare @id varchar(11)
declare @lname varchar(40)
declare @fname varchar(20)
declare @phone char(15)
declare @add varchar(40)
declare @city varchar(20)
declare @state char(2)
declare @zip char(5)
declare @con bit
---读取游标的记录
fetch first from au_cursors
into @id,@lname,@fname,@phone,@add,@city,@state,@zip,@con
print '读取表authors的数据是:'
while(@@fetch_status=0)
begin
print 'id' +@id + 'lname'+@lname+
'fname' +@fname+
'phone'+@phone+ 'address'+ @add +'city'+@city
+'state'+@state +'zip' +@zip add 'contract'+@con
fetch next from authors_cursor into @id,@lname,@fname,@phone,@add,@city,@state,@zip,@con
end
有什么错误请指教啊~!

/*打开该游标*/
open au_cursors
与你定义的au_cursor 名称不一样
你游标的名称老是在变 如:
declare au_cursor cursor
open au_cursors
fetch first from au_cursors
fetch next from authors_cursor
下次认真点. 加油。