Example
DECLARE
num NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('Welcome to the Program');
num := -2;
IF num > 0 THEN
DBMS_OUTPUT.PUT_LINE('You entered a positive number.');
GOTO end_of_program;
ELSE
DBMS_OUTPUT.PUT_LINE('You entered either zero or a negative number.');
END IF;
<<end_of_program>>
DBMS_OUTPUT.PUT_LINE('End of the Program');
END;
Output:
Explanation of the Code
- Displays a welcome message to the user when the program starts.
- Input a number.
- The program checks if the input number is less than or equal to zero. If it is, the program jumps using the GOTO statement.
- If the number is positive (not zero or negative), this line gets executed, indicating the input is a positive number.
- If the input number by user is zero or negative, this line gets executed, indicating that the input is either zero or a negative number.
- Marks the end of the program and displays a concluding message.
PL/SQL GOTO Statement
PL/SQL also known as Procedural Language/Structured Query Language, PL/SQL is a powerful programming language used in Oracle databases to do interaction with data. One of its features is the GOTO statement, which helps control how a program flows by allowing it to jump to specific statements within the same part of the program.