例子,sql数据库带输出的游标。
declare @count int
declare @tablename varchar(100)
declare @sql nvarchar(4000)
declare mycursor cursor for
select name from sysobjects where name like 'test____'
open mycursor
fetch next from mycursor into @tablename
while(@@FETCH_STATUS=0)
begin
set @sql='select @count=COUNT(*) from ' + @tablename
exec sp_executesql @sql,N'@count int output' ,@count=@count output
--print @tablename
if(@count=0)
begin
print @tablename
print @count
end
fetch next from mycursor into @tablename
end
close mycursor
deallocate mycursor