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>