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