关于游标的问题 急!~~在现等

小K-最佳损友 2003-11-17 05:29:22
为何下面两个游标中经过循环只插到主表与副表中一条记录,而我查过数据库中应该正确的记录有4条,也就是说循环为何不继续下去,是否游标的开关的写法有问题,不好意思,本人菜鸟,PB用了不到一个月
declare cur_cust cursor for
select distinct custcode from bs.mbs_plan
where storeid = :ls_storeid
and empid = :ls_empid
and qty > 0
group by custcode;

open cur_cust;

fetch cur_cust into :ls_custcode;
do while sqlca.sqlcode = 0
if ls_custcode = '' or IsNull(ls_custcode) then
MessageBox('提示','未找到生成采购订单的信息!!',StopSign!);
exit;
end if
ll_row = ds_popoh.InsertRow(0);
ls_runno = gf_get_serial_number("POD");
ds_popoh.setitem(ll_row,"doctype","POD")
ds_popoh.setitem(ll_row,"curr",ls_code)
ds_popoh.setitem(ll_row,"custcode",ls_custcode)
ds_popoh.setitem(ll_row,"lcy",gf_local_rate())
ds_popoh.setitem(ll_row,"fcy",gf_foreign_rate())
ds_popoh.setitem(ll_row,"storeid",ls_storeid)
ds_popoh.setitem(ll_row,"runno",ls_runno)
ds_popoh.setitem(ll_row,"datedoc",gpf_user.uf_get_servertime())
ds_popoh.setitem(ll_row,"validity",15)
ds_popoh.setitem(ll_row,"datedue",RelativeDate(date(gpf_user.uf_get_servertime()),15))
ds_popoh.setitem(ll_row,"dateship",RelativeDate(date(gpf_user.uf_get_servertime()),15))
ds_popoh.setitem(ll_row,"writetime",gpf_user.uf_get_servertime())
ds_popoh.setitem(ll_row,"writer",gpf_user.uf_get_employeeid())
ds_popoh.setitem(ll_row,"gstind","N")
ds_popoh.setitem(ll_row,"empid",ls_empid)
Decimal lc_qty,ldc_realprice,ldc_unitprice,ldc_gstpercent
DateTime ld_datedoc
String ls_issu,ls_serialno,ls_qtyuom,ls_partdesc,ls_partno
declare cur_list cursor for
select t1.qty,t2.partdesc,t2.issu,t2.serialno,t2.qtyuom,t1.datedoc,t1.partno,t1.price,t2.whoprice,t2.gstpercent
from bs.mbs_plan t1,mi.m_mer t2
where storeid = :ls_storeid
and empid = :ls_empid
and qty > 0
and t1.partno = t2.partno
and t1.custcode = :ls_custcode;

open cur_list;
fetch cur_list into :lc_qty,:ls_partdesc,:ls_issu,:ls_serialno,:ls_qtyuom,:ld_datedoc,:ls_partno,:ldc_realprice,:ldc_unitprice,:ldc_gstpercent;
do while sqlca.sqlcode = 0
ll_row2 = ds_popod.InsertRow(0);
ds_popod.SetItem(ll_row2,"doctype",'POD');
ds_popod.SetItem(ll_row2,"storeid",ls_storeid);
ds_popod.setitem(ll_row2,"gstpercent",ldc_gstpercent)
select dvaluse into :ls_invtdo from mi.m_md_pref where dcode='PROG' and ddcode='POD_A';
Choose Case ls_invtdo
Case 'Y'
ds_popod.SetItem(ll_row,"auditor",ls_empid)
ds_popod.SetItem(ll_row,"audit","Y")
ds_popoh.setitem(ll_row,"validation","P")
Case 'N'
ds_popod.SetItem(ll_row,"auditor","")
ds_popod.SetItem(ll_row,"audit","U")
ds_popoh.setitem(ll_row,"validation","I")
Case else
ds_popod.SetItem(ll_row,"auditor","")
ds_popod.SetItem(ll_row,"audit","U")
ds_popoh.setitem(ll_row,"validation","I")
End Choose
fetch cur_list into :lc_qty,:ls_partdesc,:ls_issu,:ls_serialno,:ls_qtyuom,:ld_datedoc,:ls_partno,:ldc_realprice,:ldc_unitprice,:ldc_gstpercent;
loop
close cur_list;
fetch cur_cust into :ls_custcode;
loop

close cur_cust;
...全文
60 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
klbt 2003-12-10
  • 打赏
  • 举报
回复
游标问题多多,建议用数据窗口代替
ghosthjt 2003-12-10
  • 打赏
  • 举报
回复
是的,由游没有关闭!
dotnba 2003-12-10
  • 打赏
  • 举报
回复
解决没有?
liliang800207 2003-11-17
  • 打赏
  • 举报
回复
这是因为
在你的第一个游标中,你使用的是默认事务sqlca
在你声明第二个游标前,第一个游标没有关闭,换句话说,你的事务sqlca还被占用,
没有释放,而你的第二个游标还用事务sqlca,这样产生了冲突!!!
解决方法:
再声明一个事务mysql
第二个游标声明后加上using mysqlca

肯定行,因为我遇到过,足足耗了我两天
mittee 2003-11-17
  • 打赏
  • 举报
回复
不好意思,应该是:

do until sqlca.sqlcode = -1
mittee 2003-11-17
  • 打赏
  • 举报
回复
do until sqlca.sqlcode <> -1
...............
loop

1,080

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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