【问题标题】:how to replace the while by a cursor? [closed]如何用光标替换while? [关闭]
【发布时间】:2013-09-16 11:41:33
【问题描述】:

我想用光标替换下面的while循环,我尝试了很多例子但到现在都没有成功,你能帮我吗?

set @tableboundary =( select count(*) as counts from @From_T)
 while @counter < @tableboundary
begin
set @Enti = (select Entities from @From_T where id= @counter)
    Insert into @Temp_Tamale ( Entities) select  value FROM MarMo.dbo.udf_ParseInto(@Enti, ',', '', '')
    set @counter = @counter + 1 
end 

【问题讨论】:

  • 而对于 what database 这是? mysql?甲骨文?后格雷斯?跨基地? SQL 服务器?数据库2?完全是别的东西????
  • 我用的是SQL,是存储过程
  • SQL 只是 查询语言 - 同样,这仍然不是 数据库产品
  • 如下所述,单个查询就可以完成这项工作,无论如何恕我直言,使用游标不会让您绕过WHILE-Loop....WHILE @@FETCH_STATUS = 0...

标签: sql stored-procedures cursor


【解决方案1】:

既然可以使用单个 SQL 语句,为什么还要使用游标?

Insert into @Temp_Tamale (Entities)
    select value
    from @From_T t cross apply
         MarMo.dbo.udf_ParseInto(t.Entities, ',', '', '');

【讨论】:

    猜你喜欢
    • 2019-09-13
    • 1970-01-01
    • 2012-05-05
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多