Home > Database > Mysql Tutorial > oracle存储过程中return和exit区别概述及测试

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

WBOY
Release: 2016-06-07 17:56:01
Original
1284 people have browsed it

至于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 跳出本次循环,下次继续执行本次循环
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template