>  기사  >  데이터 베이스  >  oracle存储过程中return和exit区别概述及测试

oracle存储过程中return和exit区别概述及测试

WBOY
WBOY원래의
2016-06-07 17:56:011255검색

至于return和exit在oracle存储过程中的应用,有些新手朋友们还是比较容易混淆的,本文将针对这两个关键字进行详细对比下,感兴趣的你可以参考下,希望可以帮助到你

代码如下:
create or replace procedure Test5(o_cellphone in varchar2) is
v_cellphone cc_quiz_stat.cellphone %type;
v_name cc_quiz_stat %rowtype;
v_state cc_quiz_stat.state %type;
begin
declare
cursor cur_cc is
select * from cc_quiz_stat;
cursor cur_jc(v_n varchar2) is
select state from cc_quiz_stat;
begin
open cur_cc;
loop
fetch cur_cc
into v_name;
exit when cur_cc%notfound;
open cur_jc(o_cellphone);
loop
fetch cur_jc
into v_state;
exit when cur_jc %notfound;
if (o_cellphone = v_name.cellphone) then
return;
else
dbms_output.put_line('手机号' || v_name.cellphone || '省份' ||
v_state);
end if;
end loop;
close cur_jc;
end loop;
close cur_cc;
end;
end Test5;

执行结果
手机号18900000000省份全国
手机号18900000000省份南京
手机号18900000000省份天津
手机号18900000000省份 上海
手机号18900000000省份北京
代码如下:
create or replace procedure Test5(o_cellphone in varchar2) is
v_cellphone cc_quiz_stat.cellphone %type;
v_name cc_quiz_stat %rowtype;
v_state cc_quiz_stat.state %type;
begin
declare
cursor cur_cc is
select * from cc_quiz_stat;
cursor cur_jc(v_n varchar2) is
select state from cc_quiz_stat;
begin
open cur_cc;
loop
fetch cur_cc
into v_name;
exit when cur_cc%notfound;
open cur_jc(o_cellphone);
loop
fetch cur_jc
into v_state;
exit when cur_jc %notfound;
if (o_cellphone = v_name.cellphone) then
exit;
else
dbms_output.put_line('手机号' || v_name.cellphone || '省份' ||
v_state);
end if;
end loop;
close cur_jc;
end loop;
close cur_cc;
end;
end Test5;

执行结果
手机号18900000000省份全国
手机号18900000000省份南京
手机号18900000000省份天津
手机号18900000000省份 上海
手机号18900000000省份北京
手机号18900000002省份全国
手机号18900000002省份南京
手机号18900000002省份天津
手机号18900000002省份 上海
手机号18900000002省份北京
手机号18900000003省份全国
手机号18900000003省份南京
手机号18900000003省份天津
手机号18900000003省份 上海
手机号18900000003省份北京
手机号18900000004省份全国
手机号18900000004省份南京
手机号18900000004省份天津
手机号18900000004省份 上海
手机号18900000004省份北京

return 跳出整个循环,本循环后面的不再执行,
exit 跳出本次循环,下次继续执行本次循环
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.