cursor 定义错误 请指教

yiyi0518 2009-11-07 03:12:53
declare @MaxRun_Times_flu int
select @MaxRun_Times_flu = 5

declare @cur_flu cursor for select top @MaxRun_Times_flu fname from #tmp_file


不清楚这样写有啥不对的地方
...全文
89 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxl616zxl 2009-11-08
  • 打赏
  • 举报
回复
定义游标不要@符号
zxl616zxl 2009-11-08
  • 打赏
  • 举报
回复
declare @MaxRun_Times_flu int
set @MaxRun_Times_flu = 5

declare cur_flu cursor for select top (@MaxRun_Times_flu) fname from files


这样就没问题了
gxzh0817 2009-11-08
  • 打赏
  • 举报
回复
对2005 来说应该可以的啊
yiyi0518 2009-11-08
  • 打赏
  • 举报
回复
我用的是2000 的, 看样子还是得用别的方法了, 谢谢各位了~~
cxmcxm 2009-11-07
  • 打赏
  • 举报
回复
对2000不支持top 变量
对2005 top 后变量需加括号
declare @MaxRun_Times_flu int 
select @MaxRun_Times_flu = 5

declare @cur_flu cursor for select top (@MaxRun_Times_flu) fname from #tmp_file

  • 打赏
  • 举报
回复
declare @cur_flu cursor for select top @MaxRun_Times_flu fname from #tmp_file

这个语句本身有问题。游标是一行一行的来取的,你一次取5行,行得通吗?
yiyi0518 2009-11-07
  • 打赏
  • 举报
回复
要把文件名取出来 然后倒入数据库的


换个思路,把文件名全部取出来存变量里, 用的时候再分割开来也可以做
feixianxxx 2009-11-07
  • 打赏
  • 举报
回复
。。。扯了。。。
游标有这么用么?
SQL77 2009-11-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yiyi0518 的回复:]
引用 1 楼 sql77 的回复:
SQL codedeclare@MaxRun_Times_fluintselect@MaxRun_Times_flu=5declare@cur_flucursorforEXEC('select top'+LTRIM(@MaxRun_Times_flu )+' fname from #tmp_file')

不支持TOP变量


还是不对哦  郁闷了~·
[/Quote]
那你干嘛要一条一条的取呀
yiyi0518 2009-11-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sql77 的回复:]
SQL codedeclare@MaxRun_Times_fluintselect@MaxRun_Times_flu=5declare@cur_flucursorforEXEC('select top'+LTRIM(@MaxRun_Times_flu )+' fname from #tmp_file')

不支持TOP变量
[/Quote]

还是不对哦 郁闷了~·
--小F-- 2009-11-07
  • 打赏
  • 举报
回复
支持11 这个需要用动态语句
SQL77 2009-11-07
  • 打赏
  • 举报
回复
declare @MaxRun_Times_flu int 
select @MaxRun_Times_flu = 5

declare @cur_flu cursor for
EXEC('select top '+LTRIM(@MaxRun_Times_flu )+' fname from #tmp_file ')


不支持TOP变量

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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