当前位置: 代码迷 >> PB >> 游标嵌套的内层取不到值,该如何解决
  详细解决方案

游标嵌套的内层取不到值,该如何解决

热度:38   发布时间:2016-04-29 08:38:32.0
游标嵌套的内层取不到值
我用pb11.5 mssql2000
代码:
 DECLARE mycursor CURSOR FOR  
  SELECT DISTINCT jl.factory  
  FROM jl
  WHERE (jl.jl_time >= :tt_date)AND
  (jl.jl_time < :tom_date)
ORDER BY jl.factory asc;
open mycursor;
do while sqlca.sqlcode = 0
fetch mycursor into :factory;
if sqlca.sqlcode = 100 then
exit
end if
DECLARE mycursor2 CURSOR FOR  
  SELECT DISTINCT jl.norms  
  FROM jl
  WHERE (jl.factory = :factory)AND
(jl.jl_time >= :tt_date)AND
  (jl.jl_time < :tom_date)  
ORDER BY jl.norms asc;
open mycursor2;
do while sqlca.sqlcode = 0
fetch mycursor2 into :norms;  
if sqlca.sqlcode = 100 then
exit
end if
...................
  loop
close mycursor2;
loop
close mycursor;

外层factory取到了值,可内层norms取不到。提示cursor is not open。
这段代码在pb8.0中动行的很好,可在pb11.5中就不行。高手看看是什么问题?

------解决方案--------------------
为什么要用两个游标,这样一个游标不行吗
SQL code
SELECT DISTINCT jl.factory, jl.norms    FROM jl   WHERE (jl.jl_time >= :tt_date)AND         (jl.jl_time < :tom_date) ORDER BY jl.factory asc, jl.norms asc;
  相关解决方案