1. Branching structure
In PL/SQL, the IF keyword is used as the starting segment of the program for the point structure.
There are several branching structures in general:
1) If Condition then statement end if;
2) If Condition then statement
Else then statement
End If;
3) If Condition then statement
elsif condition Then statement
...
Else then statement
End If;
The structure corresponding to the if () {},if () {}else () {},if () {}else if () {}...else{} in other languages
In addition, PL/SQL also provides the case keyword as an identifying segment of the branching structure.
There are several ways to use case:
1) Single-value matching for a field
Case Column1
When value1 then statement
When value2 then statement
...
End case;
This structure is similar to the switch structure in other languages.
2) Use case: When structure to express if: else conditional syntax
Case
When condition then statement
When condition then statement
...
End case;
2. Cyclic structure
In PL/SQL, the specific loop structure has the following types:
1) for
For i in Rs.first. Rs.last Loop
end Loop;
This structure is concise and efficient when traversing the collection that the cursor points to, which enables the automatic management of cursors: including cursors open, close, and auto Fetch.
Example:
Declare
cursor C_emp is
select * from EMP;
Emp_record Emp%rowtype;
begin
For Emp_record in C_emp
Loop
Dbms_output.put_line (emp_record.empno);
end Loop;
end;
This PL/SQL program does not open a cursor, does not use a FETCH statement, and does not close the cursor, but uses the for. The in structure automates these tasks automatically, so it is simple, efficient and error-prone.
2) Loop when
Loop
exit when (statement)
end Loop;
3) Loop while
While (statement)
Loop
end Loop;
4) Goto
Loop
if (statement) then goto label_name
End If;
end Loop;
<<label_name>>
In PL/SQL, you can use the form <<label_name>> to define a label that uses the GOTO keyword to jump to the label as it executes, thus ending the loop body.
This article from "Notdebug" blog, reproduced please contact the author!
PL/SQL syntax