PL/SQL Control Statement Exercises: Print 1st n numbers
PL/SQL Control Statement: Exercise-23 with Solution
Write a program in PL/SQL to print 1st n numbers.
Sample Solution:
PL/SQL Code:
DECLARE
n number:= &first_n_number;
BEGIN
DBMS_OUTPUT.PUT_LINE ('The first '||n||' numbers are: ');
for i in 1..n loop
dbms_output.put(i||' ');
END LOOP;
dbms_output.new_line;
END;
/
Flowchart:
Sample Output:
Enter value for first_n_number: 10 old 2: n number:= &first_n_number; new 2: n number:= 10; The first 10 numbers are: 1 2 3 4 5 6 7 8 9 10 PL/SQL procedure successfully completed.
Improve this sample solution and post your code through Disqus
Previous: Write a program in PL/SQL using loop with CONTINUE WHEN statement.
Next: Write a program in PL/SQL to print 1st n numbers with a difference of 3 and starting from 1.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics