1. GOTO, mainly used for jump, but will disrupt our program logic. It is generally not used. It can implement the RETURN and EXIT functions.
2. RETURN: RETURN to the end of the program and end the program.
3. EXIT, mainly used to EXIT the current loop, which is equivalent to break in java.
4. You can use custom exception methods to implement the continue function in java.
Comparison between them
- -- The GOTO here is equivalent to the following EXIT usage
- BEGIN
- FOR I IN1..2LOOP
- IF I =2THEN
- GOTO label;
- End if;
- Dbms_output.put_line ('I ='| I );
- End loop;
- <Label>
- Dbms_output.put_line ('The last ...');
- END;
- /
- I =1
- The last...
- PL/SQL procedure successfully completed.
- BEGIN
- FOR I IN1..2LOOP
- IF I =2THEN
- -- GOTO label;
- EXIT;
- End if;
- Dbms_output.put_line ('I ='| I );
- End loop;
- <Label>
- Dbms_output.put_line ('The last ...');
- END;
- /
- I =1
- The last...
- PL/SQL procedure successfully completed.
- BEGIN
- FOR I IN1..2LOOP
- IF I =2THEN
- -- GOTO label;
- -- EXIT;
- RETURN;
- End if;
- Dbms_output.put_line ('I ='| I );
- End loop;
- <Label>
- Dbms_output.put_line ('The last ...');
- END;
- /
- I =1
- PL/SQL procedure successfully completed.
- -- The following is equivalent to the above RETURN
- BEGIN
- FOR I IN1..2LOOP
- IF I =2THEN
- GOTO label;
- -- EXIT;
- -- RETURN;
- End if;
- Dbms_output.put_line ('I ='| I );
- End loop;
- Dbms_output.put_line ('The last ...');
- <Label>
- NULL; -- This NULL cannot be omitted. <label> it cannot be earlier than END; end loop;
- END;
- /
- I =1
- PL/SQL procedure successfully completed.
Customize exceptions to implement the continue Function
- DECLARE
- E_My_Exception EXCEPTION;
- -- PRAGMA EXCEPTION_INIT (e_My_Exception ,-1401);
- BEGIN
- FOR I IN1..2LOOP
- BEGIN
- IF I =2THEN
- RAISE e_My_Exception;
- End if;
- Dbms_output.put_line ('I ='| I );
- EXCEPTION
- WHEN e_My_Exception THEN
- NULL;
- END;
- End loop;
- Dbms_output.put_line ('The last ...');
- END;
- /