0

I am working on a loop to bring back the times tables from 1-12. I have completed this by using the following:

BEGIN
FOR i IN 1..12
LOOP
FOR j IN (i)..12
LOOP
dbms_output.put_line ( (i ) || '*' || (j ) || ('=') || (i*j) );
END LOOP;
END LOOP;
END;
/

And it brings back:

1*1=1
1*2=2
1*3=3
1*4=4
1*5=5
1*6=6
1*7=7
1*8=8
1*9=9
1*10=10
1*11=11
1*12=12
2*2=4
2*3=6
2*4=8
etc..

it brings back all the times tables like i wanted. Now i want it to bring back a title for each set, how would i do this? for e.g.

1 timetable 
1*1=1
1*2=2
1*3=3
1*4=4
1*5=5
1*6=6
1*7=7
1*8=8
1*9=9
1*10=10
1*11=11
1*12=12
2 timestable
2*2=4
2*3=6
2*4=8

Is this possible?

Thanks

1 Answers1

2

Try;

BEGIN
    FOR i IN 1..12 LOOP
        dbms_output.put_line(to_char(i) || ' timetable');
        FOR j IN (i)..12 LOOP
            dbms_output.put_line ( (i ) || '*' || (j ) || ('=') || (i*j) );
        END LOOP;
    END LOOP;
END;
/
Praveen
  • 8,945
  • 4
  • 31
  • 49