PL/SQL Program to Print Table of a number

In this example, you will write PL/SQL program to print a multiplication table of a number entered by the user.

PL/SQL Program to Print Table of a number using while loop

Here you will print a multiplication table of a number entered by the user using while loop.

declare
i number:=1;
n number;
begin
n:=&n;
while(i<=10)
loop
  dbms_output.put_line( n || ' * ' || i || ' = ' || n*i);
  i:=i+1;
end loop;
end;
/

PL/SQL Program to Print Table of a number using for loop

Here you will print a multiplication table of a number entered by the user using for loop.

declare
i number;
n number;
begin
n:=&n;
for i in 1..10
loop
 dbms_output.put_line( n || ' * ' || i || ' = ' || n*i);
end loop;
end;
/

output

Enter value for n: 5
old   5: n:=&n;
new   5: n:=5;
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50