初学SQL 游标。小弟有点不明白 顶有分。在线等

kke_007 2010-11-04 03:53:28

create proc mytest
as
begin
declare @t_id nchar(12)
declare @t_title nchar(40)
/*问题 是不是查询语句都是定死的,如果是这样不是显的很不灵活。*/
declare cur_test cursor for select t_id,t_title from test where 1=1
open
cur_test
fetch next from cur_test into @t_id,@t_title while @@fetch_status=0
begin
/*这里可以写IF ELSE 做一些判断等等*/
print +' '+@t_id+' '+@t_title
fetch next from cur_test into @t_id,@t_title
end
close cur_test
deallocate cur_test

end


是不是查询语句都是定死的,如果是这样不是显的很不灵活
如果不定死上面的例子应该怎么改呢?
怎么样他的语句加上参数?

如果我定议两个游标。第二游标的我条件是来自第一个游标里来的。需要怎么写
初学。。
...全文
103 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
guo88412555 2010-11-09
  • 打赏
  • 举报
回复
存储程序要输入的参数
xinyuetonghua 2010-11-07
  • 打赏
  • 举报
回复
mytest(@tmp nchar(10))
xinyuetonghua 2010-11-07
  • 打赏
  • 举报
回复
create proc mytest“"""""(@tmp nchar(10))""""""没明白,能讲讲吗,
这是什么意思啊,
kevn 2010-11-04
  • 打赏
  • 举报
回复
如果真要调用你两个游标嵌套,理论上也不是不可以,就在你的print那写
kevn 2010-11-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 kke_007 的回复:]
明白。。
还有个问题

如果我定议两个游标。第二游标的我条件是来自第一个游标里来的某一个
那怎么写呢·?
[/Quote]

。。。游标能少用就少用吧。。容易出问题的
kevn 2010-11-04
  • 打赏
  • 举报
回复

create proc mytest(@tmp nchar(10))
as
begin
declare @t_id nchar(12)
declare @t_title nchar(40)
/*问题 是不是查询语句都是定死的,如果是这样不是显的很不灵活。*/
declare cur_test cursor for select t_id,t_title from test where col = @tmpopen
cur_test
fetch next from cur_test into @t_id,@t_title while @@fetch_status=0
begin
/*这里可以写IF ELSE 做一些判断等等*/
print +' '+@t_id+' '+@t_title
fetch next from cur_test into @t_id,@t_title
end
close cur_test
deallocate cur_test

end
kke_007 2010-11-04
  • 打赏
  • 举报
回复
明白。。
还有个问题

如果我定议两个游标。第二游标的我条件是来自第一个游标里来的某一个
那怎么写呢·?
kevn 2010-11-04
  • 打赏
  • 举报
回复
存储过程带上参数

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧