A sequential control statement allows transfers to the specified statement or does nothing.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Compared with the IF and LOOP statements, the sequential control statements GOTO and NULL are less important to PL programming. PL seldom uses the GOTO statement to transfer to a specified statement. The NULL statement means no operation, and it is generally used to describe meanings and operations of conditional statements to improve readability.
GOTO statement
You can use the GOTO statement to unconditionally transfer to another position in the code block. You must predefine a label and then transfer to the label by using the GOTO statement. The label must be placed before a statement, and cannot appear inside 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
If you execute a NULL statement, no operation is executed. This statement is usually used as a placeholder. For example, you can use the NULL statement as placeholders in code debugging to avoid syntax errors.