Sequence control statements allow you to transfer control to a specified statement or skip it.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
Compared with the IF and LOOP statements, the GOTO and NULL statements in sequence control statements are less important in PL/SQL programming. The GOTO statement is rarely used to jump to a specified statement. The NULL statement does not perform any action and is typically used to improve the readability of conditional statements.
GOTO statement
The GOTO statement allows you to unconditionally jump to another location in the code block and continue execution. You need to define a label in advance and then use GOTO to jump to the label. The label must be placed before a statement, not within a statement.
Here is an example:
obclient> DECLARE
cnt NUMBER := 0;
BEGIN
WHILE cnt < 3 LOOP
DBMS_OUTPUT.PUT_LINE (cnt);
cnt := cnt + 1;
GOTO JUMP_OUT;
END LOOP;
cnt := 0;
<<JUMP_OUT>>
DBMS_OUTPUT.PUT_LINE (cnt);
END;
/
Query OK, 0 rows affected
0
1
NULL statement
The NULL statement is an empty statement that does not perform any action and is typically used as a placeholder. For example, during code debugging, if the code is not yet fully written, you can use the NULL statement as a placeholder to avoid syntax errors.
