oracle預存程序中return和exit區別概述及測試

來源:互聯網
上載者:User

複製代碼 代碼如下: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 跳出本次迴圈,下次繼續執行本次迴圈

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.