怎样在存储过程中动态的使用表名,而又可以使用游标?
2008-07-17 09:36
363 查看
--过程
create proc mypro
as
declare @a nvarchar(100),@tbname nvarchar(100)
set @tbname='sysobjects'
exec ('declare mycursor cursor for select name from '+@tbname+' where xtype=''U''')
open mycursor
fetch next from mycursor into @a
while @@fetch_status=0
begin
print @a
fetch next from mycursor into @a
end
close mycursor
deallocate mycursor
go
--执行
exec mypro
--删除过程
drop proc mypro
create proc mypro
as
declare @a nvarchar(100),@tbname nvarchar(100)
set @tbname='sysobjects'
exec ('declare mycursor cursor for select name from '+@tbname+' where xtype=''U''')
open mycursor
fetch next from mycursor into @a
while @@fetch_status=0
begin
print @a
fetch next from mycursor into @a
end
close mycursor
deallocate mycursor
go
--执行
exec mypro
--删除过程
drop proc mypro
相关文章推荐
- 存储过程DIY3----游标中可以使用子查询:
- mysql 存储过程中使用游标中使用临时表可以替代数组效果
- PL/SQL块或者存储过程中不能执行DDL,可以使用动态SQL
- 在存储过程中使用动态sql
- Mysql存储过程中游标的使用以及错误处理
- oracle 存储过程之游标(loop)使用
- 使用游标编写的存储过程进行分页
- ORACLE 存储过程使用技巧&游标技巧
- Oracle 动态SQL语句(4)之存储过程的调用与浅谈字符串的使用
- SQL的存储过程、动态语句、临时表、游标的综合应用
- Oracle 存储过程中使用cursor 游标遍历数据
- ORACLE 存储过程动态游标例子
- Oracle中加密解密的数据库函数,创建(包含游标)和使用存储过程
- 中信房屋:SQL Server在存储过程中使用游标
- 怎样查看存储过程当前正在被哪些用户使用
- 使用MySQL存储过程创建动态交叉表(1)
- oracle存储过程中 使用游标做循环封装数据集
- postgresql 游标,函数,存储过程使用例子
- Sql 存储过程加游标结合的使用
- SQL Server中在存储过程中使用游标修改表中数据