我想在sybase中创建一个while循环,循环时我的临时表“nodesNotHavingCriteria”中还有任何条目。 但我在下面创建的程序似乎永远持续下去,我认为这是因为while循环正在进行,但我似乎找不到它的理由。 有人可以帮忙吗?这对我来说似乎很好,无法找到永无止境的原因。
create PROCEDURE createCriteria
as begin
declare @uid varchar(10)
while (select count(*) from #nodesNotHavingCriteria) > 0
set rowcount 1
select @uid = nodes from #nodesNotHavingCriteria -- pull one uid from the temp table
set rowcount 0
delete from #nodesNotHavingCriteria where nodes = @uid -- delete that uid from the temp table
-- Do something with the uid you have
--insert into BacktestingCriteria (nodeId,hierarchyViewId,varCriteriaId,pnlCriteriaId) values
-- (@uid,16008,16,3)
--insert into BacktestingCriteria (nodeId,hierarchyViewId,varCriteriaId,pnlCriteriaId) values
--(@uid,16008,16,4)
end
答案 0 :(得分:2)
我认为你的while循环不再是检查标准了。它只选择一次计数并检查> 0永远
也许你应该尝试类似(js中的伪代码)
var count = select count(*) from #nodesNotHavingCriteria;
while(count > 0)
// Do anything
count = select count(*) from #nodesNotHavingCriteria;
我也不了解sybase,但是从中删除后,#nodesNotHavingCriteria真的更新了吗?
答案 1 :(得分:0)
create PROCEDURE createCriteria
as begin
declare @uid varchar(10)
while ((select count(*) from #nodesNotHavingCriteria)>0)
begin
set rowcount 1
select @uid = nodes from #nodesNotHavingCriteria -- pull one uid from the temp table
set rowcount 0
delete from #nodesNotHavingCriteria where nodes = @uid -- delete that uid from the temp table
-- Do something with the uid you have
insert into BacktestingCriteria (nodeId,hierarchyViewId,varCriteriaId,pnlCriteriaId) values
(@uid,16008,16,3)
insert into BacktestingCriteria (nodeId,hierarchyViewId,varCriteriaId,pnlCriteriaId) values
(@uid,16008,16,4)
end
end