Differences between return and exit in oracle stored procedures

Source: Internet
Author: User
As for the application of return and exit in oracle stored procedures, some new users are still relatively confused. This article will compare these two keywords in detail. For more information, see, hope to help you

As for the application of return and exit in oracle stored procedures, some new users are still relatively confused. This article will compare these two keywords in detail. For more information, see, hope to help you

The Code is as follows:
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 ('mobile phone no. '| v_name.cellphone | 'province' |
V_state );
End if;
End loop;
Close cur_jc;
End loop;
Close cur_cc;
End;
End Test5;

Execution result
Mobile phone no. 18900000000 provinces nationwide
Mobile phone number 18900000000 province Nanjing
Mobile phone number 18900000000 province Tianjin
Mobile phone number 18900000000 province Shanghai
Mobile phone number 18900000000 province Beijing
The Code is as follows:
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 ('mobile phone no. '| v_name.cellphone | 'province' |
V_state );
End if;
End loop;
Close cur_jc;
End loop;
Close cur_cc;
End;
End Test5;

Execution result
Mobile phone no. 18900000000 provinces nationwide
Mobile phone number 18900000000 province Nanjing
Mobile phone number 18900000000 province Tianjin
Mobile phone number 18900000000 province Shanghai
Mobile phone number 18900000000 province Beijing
Mobile phone no. 18900000002 provinces nationwide
Mobile phone number 18900000002 province Nanjing
Mobile phone number 18900000002 province Tianjin
Mobile phone number 18900000002 province Shanghai
Mobile phone number 18900000002 province Beijing
Mobile phone no. 18900000003 provinces nationwide
Mobile phone number 18900000003 province Nanjing
Mobile phone number 18900000003 province Tianjin
Mobile phone number 18900000003 province Shanghai
Mobile phone number 18900000003 province Beijing
Mobile phone no. 18900000004 provinces nationwide
Mobile phone number 18900000004 province Nanjing
Mobile phone number 18900000004 province Tianjin
Mobile phone number 18900000004 province Shanghai
Mobile phone number 18900000004 province Beijing

The return Statement jumps out of the entire loop and is not executed after this loop,
Exit jumps out of this loop and continues executing this loop next time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.