当前位置: 数据库>oracle
oracle存储过程中return和exit区别概述及测试
来源: 互联网 发布时间:2014-09-07
本文导语: 代码如下: 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...
代码如下:
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 跳出本次循环,下次继续执行本次循环