The order in which PL/SQL's IF statements are executed

Source: Internet
Author: User

The syntax of the IF statement for PL/SQL is defined as follows:

IF condition Then

{...} statements ...}

elsif condition Then

{...} statements ...}

ELSE

{...} statements ...}

END IF;


Because PL/SQL is not like a high-level language, there are no curly braces, and if statements contains more than one operation, will these operations be performed?

Here is a function to do an experiment to verify the order of execution of the IF statement:

<span style= "FONT-SIZE:18PX;" >create or Replace function testif (v_i in number)   return number as   begin    If v_i<0       then          dbms_ Output.put_line (' Output content 1 ');         Dbms_output.put_line (' Output content 2 ');         Dbms_output.put_line (' Output content 3 ');    elsif V_i=1 then         dbms_output.put_line (' Output content 4 ');         Dbms_output.put_line (' Output content 5 ');    elsif v_i=2 then          dbms_output.put_line (' output content 6 ');           Dbms_output.put_line (' Output content 7 ');       else          dbms_output.put_line (' output content 8 ');         Dbms_output.put_line (' Output content 9 ');           End If;    return V_i;end testif;</span>

If v_i=-1, the console prints out:

Output Content 1
Output Content 2
Output Content 3

If V_i=1, the console prints out:

Output Content 4
Output Content 5

If v_i=2, the console prints out:

Output Content 6
Output Content 7

If v_i=3, the console prints out:

Output Content 8
Output Content 9


Summarize:

In PL/SQL, curly braces or begin are not required. End encloses the following three statements, and the following three statements are executed together.

<span style= "FONT-SIZE:18PX;" >         dbms_output.put_line (' output content 1 ');         Dbms_output.put_line (' Output content 2 ');         Dbms_output.put_line (' Output Content 3 ');</span>



The order in which PL/SQL's IF statements are 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.