Document 4 of PL/SQL language development Reference Manual: PL/SQL control statements
PL/SQL language development Reference Manual
1. Condition statements
If boolean_expression1 (condition 1) Then <br/>... <br/> elsif boolean_expression2 (condition 2) then/* Note that elsif is not elseif */<br/>... /* The else Statement (elsif) is not required, but the end if; is required */<br/> else <br/>... <br/> end if;
Note:
1) when there are multiple boolean expressions, and (and), or (OR), not (not)
2) the condition is false and true;
2. Loop statements
1) loop
Loop <br/>... (loop body) <br/> If boolean_expr (condition) Then/* adds a Condition Statement to exit the loop when the condition is met */<br/> exit; /* exit when boolean_expr */<br/> end if; <br/> end loop;
2) while loop
While boolean_expr (condition) loop/* boolean_expr loop condition */<br/>... (loop body) <br/> end loop;
3) For Loop
For loop_counter in [reverse] low_bound .. high_bound loop <br/>/* indicates two points in the range from low_blound to high_bound */<br/>... (loop body) <br/> end loop;
Example:
For v_cnt in 1 .. 5 loop <br/> select * into v_emp from s_emp where id = v_cnt;
Note:
A. When the reverse keyword is added, it indicates that the value is decreasing, from the End boundary to the start boundary. The decreasing step is one. If the value is not added, the value ranges from the start boundary to the end boundary. The decreasing step is one;
B. Start boundary of low_blound; end bound of high_bound;
3. GOTO statementGoto label_name;
1) only internal blocks can be jumped to external blocks;
2) Set tags: <>
3) Example:
Loop <br/>... <br/> If D % rowcount = 50 then <br/> goto l_close; <br/> end if; <br/>... <br/> end loop; <br/> <l_close> :...
4. null statement
Empty the statement in the statement block to supplement the statement integrity.
Example:
If boolean_expr then <br/>... <br/> else NULL; <br/> end if;
5. SQL in PL/SQL
1) only dml SQL and transaction control SQL can be directly used in PL/SQL;
2) dynamic SQL statements in PL/SQL can use all valid SQL statements, including DDL;
3) dynamic SQL statements are dynamically generated at run time, and then analyzed and executed;
4) There are two types of dynamic SQL in PL/SQL: local dynamic SQL and dbms_ SQL packages;