PL/SQL Process Control statements
Describes the Process Control statements for PL/SQL, including the following three classes:
Control statement: IF statement
Loop statement: Loop statement, exit statement
Sequential statement: Goto statement, NULL statement
①if statements
IF < Boolean expressions > Then
PL/SQL and statements;
elsif< other Boolean expressions > Then
other statements;
elsif< other Boolean expressions > Then
other statements;
ELSE
other statements;
END IF;
Example:
Declare
v_emp_name employees.last_name%type;
v_emp_sal Employees.salary%type;
v_emp_sal_level varchar2 (20);
Begin
select Last_name,salary into v_emp_name,v_emp_sal from employees where employee_ id = 150;
if (v_emp_sal >= 10000) then v_emp_sal_level: = ' Salary >= 10000 ';
elsif (v_emp_sal >=) then v_emp_sal_level: = ' 5000<= salary < 10000 ';
Else V_emp_sal_level: = ' salary < 5000 ';
End If;
dbms_output.put_line (v_emp_name| | ', ' | | v_emp_sal| | ', ' | | V_emp_sal_level);
End;
②case-expression
Case Selector
When Expression1 then RESULT1
When Expression2 then RESULT2
When Expressionn then RESULTN
[ELSE resultn+1]
END;
PL/SQL Process Control statements