游标可以嵌套循环吗?
boolean lb_continue6,lb_6
declare cu_pcn6 cursor for
select id,p_cn from user_m where s_cn = :ls_pcn5;
open cu_pcn6;
Do while lb_continue6
Fetch cu_pcn6 into :li_userid6,:ls_pcn6;
if sqlca.sqlcode = 0 then
declare cu_assess6 cursor for
select assess from orderbill
where userid = :li_userid6
and year(makedate) = :li_year
and month(makedate) = :li_month ;
open cu_assess6;
Do while lb_6
Fetch cu_assess6 into :ld_assess6;
if sqlca.sqlcode = 0 then ld_total6 = ld_total6 + ld_assess6
else
lb_6 = false
end if
Loop
close cu_assess6;
else
lb_continue6 = false
end if
Loop
close cu_pcn6;
declare cu_pcn6 cursor for
select id,p_cn from user_m where s_cn = :ls_pcn5;
open cu_pcn6;
Do while lb_continue6
Fetch cu_pcn6 into :li_userid6,:ls_pcn6;
if sqlca.sqlcode = 0 then
declare cu_assess6 cursor for
select assess from orderbill
where userid = :li_userid6
and year(makedate) = :li_year
and month(makedate) = :li_month ;
open cu_assess6;
Do while lb_6
Fetch cu_assess6 into :ld_assess6;
if sqlca.sqlcode = 0 then ld_total6 = ld_total6 + ld_assess6
else
lb_6 = false
end if
Loop
close cu_assess6;
else
lb_continue6 = false
end if
Loop
close cu_pcn6;
...全文
相关推荐
mysql 多个游标依次执行
mysql存储过程 多个游标循环(依次执行,非嵌套循环)REPEAT循环。有需要的可自行下载。
ORACLE中游标的使用.pdf
ORACLE中游标的使用.pdf
SQL Server游标的使用/关闭/释放/优化小结
游标打破了这一查询的思考是面向集合的规则,游标使得我们思考方式变为逐行进行,接下来为大家介绍下游标的使用感兴趣的朋友可以参考下哈,希望可以帮助到你
Mysql的游标的定义使用及关闭深入分析
Mysql从5.0开始支持存储过程和trigger,给我们喜欢用mysql的朋友们更喜欢mysql的理由了,语法上和PL/SQL有差别,不过搞过编程的人都知道,语法不是问题,关键是思想,大致了解语法后,就从变量定义,循环,判断,游标,异常处理这个几个方面详细学习了。关于游标的用法Mysql现在提供的还很特别,虽然使用起来没有PL/SQL那么顺手,不过使用上大致上还是一样, 定义游标 declare fetchSeqCursor cursor for select seqname, value from sys_sequence; 使用游标 open fetchSeqCursor; fetch数
SQL 学习资料 循环和游标.docx
SQL 学习资料 循环和游标.docx


