PL/SQL Control Statement Exercises: Print the value of a variable inside and outside a loop using LOOP EXIT statement
PL/SQL Control Statement: Exercise-16 with Solution
Write a program in PL/SQL to print the value of a variable inside and outside a loop using LOOP EXIT statement.
Sample Solution:
PL/SQL Code:
DECLARE
n NUMBER := 0;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE ('The value of n inside the loop is: ' || TO_CHAR(n));
n := n + 1;
IF n > 5 THEN
EXIT;
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE('The value of n outside the loop is: ' || TO_CHAR(n));
END;
/
Flowchart:
Sample Output:
SQL> / The value of n inside the loop is: 0 The value of n inside the loop is: 1 The value of n inside the loop is: 2 The value of n inside the loop is: 3 The value of n inside the loop is: 4 The value of n inside the loop is: 5 The value of n outside the loop is: 6 PL/SQL procedure successfully completed.
Improve this sample solution and post your code through Disqus
Previous: Write a PL/SQL program to display which day is a specific date.
Next: Write a program in PL/SQL to print the value of a variable inside and outside a loop using LOOP WHEN EXIT statement.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework