create or replace procedure a is
v_routeid ia_ia_bill_head.src_bill_id%TYPE; cursor term_type is SELECT l.src_bill_id
FROM ia_ia_bill_line l
where l.id = 758;begin
Open term_type;
loop
fetch term_type
into v_routeid; --从游标取值 dbms_output.put_line('1');
if term_type%notfound then
exit;
end if; end loop;
close term_type;
end a;
上面是一个最基本的存储过程。。我奇怪的是,那个游标的select明显只有1条数据,为什么会打印2次?也就是说fetch游标了2次,这肯定不对的,是我loop的时候哪里出问题了?
求教,,
create or replace procedure a is
v_routeid ia_ia_bill_head.src_bill_id%TYPE; cursor term_type is SELECT l.src_bill_id
FROM ia_ia_bill_line l
where l.id = 758;begin
Open term_type;
loop
fetch term_type
into v_routeid; --从游标取值
EXIT WHEN term_type%NOTFOUND; dbms_output.put_line('1');
end loop;
close term_type;
end a;
open term_type;
loop
fetch term_type into v_routeid;--从游标取值
exit when term_type%notfound;--判断v_routeid里面是否有值,无值时跳出;
dbms_output.put_line('1');
end loop;
end--显示1;
你写的顺序是先显示1,下面判断,明显是有值,又执行了一次,显示1,无值,跳出;
exit;
end if;
放前面的。。