PL/SQL if statement execution sequence, plsqlif statement

Source: Internet
Author: User

PL/SQL if statement execution sequence, plsqlif statement

The if statement Syntax of PL/SQL is defined as follows:

IF condition THEN

{... Statements ...}

ELSIF condition THEN

{... Statements ...}

ELSE

{... Statements ...}

End if;


Since PL/SQL is not similar to advanced languages, there is no braces. If statements contains multiple operations, will these operations be executed?

The following describes a function to perform an experiment to verify the execution sequence 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:

Output content 1
Output content 2
Output content 3

If v_ I = 1, the console prints:

Output content 4
Output content 5

If v_ I = 2, the console prints:

Output content 6
Output content 7

If v_ I = 3, the console prints:

Output content 8
Output content 9


Summary:

In PL/SQL, braces or begin. end are not required to enclose the following three statements. The following three statements are also 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>



Related Article

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.