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