cursor不能获得参数(100分)

starry 2002-11-07 05:48:01
小弟写了个存储过程,跟踪发现cursor不能获得传进来得参数v_outbd_id,
create or replace procedure dll_proc(v_outbd_id in varchar2) as
cursor cur_test
is
select inq_id,outbd_grpid from outbd_all where outbd_id=v_outbd_id and rownum<10 ;
v_inq_id varchar(20);
v_outbd_grpid number(8);
begin
open cur_test;
dbms_output.put_line(cur_test%rowcount);
loop
fetch cur_test into v_inq_id,v_outbd_grpid;
exit when (cur_test%notfound);
end loop;
close cur_test;
commit;
end dll_proc;
很是怪异啊,输出总是为0,如果把where后面得条件删掉就可以了哈,各位帮忙啊!!
...全文
36 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
starry 2002-11-07
  • 打赏
  • 举报
回复
结果是
0
0
它只执行了一次循环,郁闷
chenbf_sz 2002-11-07
  • 打赏
  • 举报
回复
你这样试试:

loop
fetch cur_test into v_inq_id,v_outbd_grpid;
dbms_output.put_line(cur_test%rowcount);
exit when (cur_test%notfound);
end loop;
close cur_test;
chenbf_sz 2002-11-07
  • 打赏
  • 举报
回复
你在关闭游标前看看。
starry 2002-11-07
  • 打赏
  • 举报
回复
我是在程序结束之后才去看rowcount得,而且我单步跟踪看过
loop
fetch cur_test into v_inq_id,v_outbd_grpid;
exit when (cur_test%notfound);
end loop;
close cur_test;
这个根本没循环,而符合条件得记录绝对是有得。
chenbf_sz 2002-11-07
  • 打赏
  • 举报
回复
你是不是这行输出总是为0?

dbms_output.put_line(cur_test%rowcount);

游标数据在FETCH之后,才会给ROWCOUNT赋值
starry 2002-11-07
  • 打赏
  • 举报
回复
用楼上这位得动态cursor也不对啊,我用的是8.1.5啊,郁闷,始终输出0,将该sql语句copy出来执行绝对是有数据得。
KingSunSha 2002-11-07
  • 打赏
  • 举报
回复
试一下这样子:
create or replace procedure dll_proc(v_outbd_id in varchar2) as
cursor cur_test(p_id) is
select inq_id,outbd_grpid
from outbd_all
where outbd_id=p_id
and rownum<10 ;
v_inq_id varchar(20);
v_outbd_grpid number(8);
begin
open cur_test(v_outbd_id);
dbms_output.put_line(cur_test%rowcount);
loop
fetch cur_test into v_inq_id,v_outbd_grpid;
exit when (cur_test%notfound);
end loop;
close cur_test;

--commit;
end dll_proc;
KingSunSha 2002-11-07
  • 打赏
  • 举报
回复
哈哈,看错了, chenbf_sz(大象)说的不错.
chenbf_sz 2002-11-07
  • 打赏
  • 举报
回复
误会了。
KingSunSha 2002-11-07
  • 打赏
  • 举报
回复
看不出什么错误.

如果用的ORACLE8I以前的版本,有可能是因为ROWNUM的问题,去掉ROWNUM的条件再试一下.
chenbf_sz 2002-11-07
  • 打赏
  • 举报
回复
open cur_test(你送入的参数值);

3,499

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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