Press "Enter" to skip to content

How to Print 1 to 10 Without Using Loop in PL/SQL?

Here I am giving an example to print 1 to 10 without using the loop in PL/SQL. You can print up to any number by changing the value 10 to any number, for example, 100.

PL/SQL Program to Print 1 to 10 Without Using Loop

In the below program, I am using PL/SQL labels instead of the loop to increment the value and print. In label named (label_main), I am incrementing the value of the variable (i) and checking if its value greater than 10 then passing control to a label named (label_end) else passing control to label (label_main). You can change the value in the IF condition from 10 to the desired number to print up to that number.

SET SERVEROUTPUT ON;

DECLARE
   i   NUMBER;
BEGIN
   i := 0;

  <<label_main>>
   i := i + 1;

   IF i > 10
   THEN
      GOTO label_end;
   END IF;

  <<label_print>>
   DBMS_OUTPUT.put_line (i);
   GOTO label_main;

  <<label_end>>
   NULL;
END;
/

Output

1
2
3
4
5
6
7
8
9
10
PL/SQL procedure successfully completed.

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *