One definition:
The Oracle Pl/sql GOTO statement is a sequential control structure available in Oracle. The GOTO statement immediately transfers program control (called "branching") unconditionally to a named Statement label O R Block label. The statement or label name must is unique in the block.
belongs to the Plsql control statement, which controls the non conditional jump to the specified label <<??? >>. Easy to control and maintain, use with caution!
Two examples:
1, simple goto statement to determine whether the number is prime:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14-15 16 |
DECLARE P VARCHAR2 (30); N Pls_integer: = 37; --Test any integer > 2 for Prime BEGIN to J in 2. Round (sqrt (n)) LOOP IF n MOD j = 0 THEN--test for prime P: = ' are not a prime number '; --Not a prime number GOTO Print_now; End IF; End LOOP; P: = ' is a prime number '; <<print_now>> Dbms_output.put_line (To_char (n) | | p); End; / |
2, use NULL to avoid the error:
?
1 2 3 4 5 6 7 8 9 10 11-12 |
DECLARE done BOOLEAN; BEGIN for I in 1. LOOP IF done THEN GOTO End_loop; End IF; <<end_loop>>-not allowed unless a executable statement follows NULL; --Add NULL statement to avoid the error end LOOP; --raises an error without the previous NULL end; / |
3. Use goto to separate a wrapping block:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
--Example with GOTO statement DECLARE V_last_name VARCHAR2 (25); V_EMP_ID Number (6): = 120; BEGIN <<get_name>> SELECT last_name into V_last_name from employees WHERE employee_id = v_emp_id; BEGIN Dbms_output.put_line (v_last_name); V_EMP_ID: = v_emp_id + 5; IF v_emp_id < THEN GOTO get_name; --branch to enclosing blocks end IF; End; End; / |
----------------------
Dylan Presents.