0

I would like to display Unique numbers dynamically. I have tried below code for the same but same number is displaying all the times.

DECLARE
a NUMBER;
BEGIN
FOR i IN 1 .. 3 LOOP

DBMS_OUTPUT.PUT_LINE(&a);
END LOOP;
END;

the above code will ask me for "a" value three times, if i pass 1,2,3 as parameters then it should display 1,2,3 but this code is displaying first(1) value three time as 1,1,1.

Could you please help me to get the required output like 1,2,3

Gani Ganesh
  • 63
  • 2
  • 10

2 Answers2

1

You can't really create an interactive program in just PL/SQL. When you put &a in the PL/SQL and run it in a tool like SQL Developer, it prompts you once for a value for a before it runs the code, using the value you typed instead of the substitution variable a.

Tony Andrews
  • 129,880
  • 21
  • 220
  • 259
0

You want to print i and not a. Also the ampersand in front of the a means you will be prompted to enter a value for a.

Gary_W
  • 9,933
  • 1
  • 22
  • 40
  • what if i want to print 101, 505, 2000 values which i passed to "a" – Gani Ganesh Aug 04 '20 at 13:38
  • 1
    @GaniGanesh I would like to respectfully suggest you review some PL/SQL documents as it seems you are working on some learning exercises. Try here: https://docs.oracle.com/database/121/LNPLS/toc.htm. – Gary_W Aug 04 '20 at 13:46