How to differentiate exit and ruturn in Stored Procedures

Source: Internet
Author: User
Tags exit in

Step 1: Test the stored procedure using exit

Create or replace procedure p_test_return_exit is

I number: = 1;
J number: = 1;
Begin

For I in 1 .. 20 Loop

Dbms_output.put_line ('output DATA = '| I );
If (I> 10) then
Exit;
End if;

End loop;

For J in 1 .. 20 Loop

Dbms_output.put_line ('output DATA = '| j );
End loop;

End p_test_return_exit;

Test results:

Output Data = 1
Output Data = 2
Output Data = 3
Output Data = 4
Output Data = 5
Output Data = 6
Output Data = 7
Output Data = 8
Output Data = 9
Output Data = 10
Output Data = 11
Output Data = 1
Output Data = 2
Output Data = 3
Output Data = 4
Output Data = 5
Output Data = 6
Output Data = 7
Output Data = 8
Output Data = 9
Output Data = 10
Output Data = 11
Output Data = 12
Output Data = 13
Output Data = 14
Output Data = 15
Output Data = 16
Output Data = 17
Output Data = 18
Output Data = 19
Output Data = 20

 

 

Step 2: Test the use of return in the Stored Procedure

Create or replace procedure p_test_return_exit is

I number: = 1;
J number: = 1;
Begin

For I in 1 .. 20 Loop

Dbms_output.put_line ('output DATA = '| I );
If (I> 10) then
Return;
End if;

End loop;

For J in 1 .. 20 Loop

Dbms_output.put_line ('output DATA = '| j );
End loop;

End p_test_return_exit;

Test results:

Output Data = 1
Output Data = 2
Output Data = 3
Output Data = 4
Output Data = 5
Output Data = 6
Output Data = 7
Output Data = 8
Output Data = 9
Output Data = 10
Output Data = 11

 

Conclusion:

Exit in the loop of the stored procedure to exit this loopProgramBut will continue to execute other program blocks of the stored procedure.

 

In the loop of the stored procedure, return exits from the current loop and exits the entire stored procedure. Other program blocks are not executed.

 

 

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.