Sequential control statements allow you to transfer to a specified statement or skip any processing.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only MySQL-compatible mode.
Compared with IF and LOOP statements, the GOTO and NULL statements in sequential control statements are less important in PL programming. The GOTO statement is rarely used to transfer to a specified statement. The NULL statement does not perform any operation and is typically used to improve readability by clarifying the meaning and operation of conditional statements.
GOTO statement
The GOTO statement allows you to unconditionally jump to another location in the code block to 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 and cannot appear in the middle of 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 operation. It 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.