I need to print numbers in pl/sql in the given format?
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
also can you tell me how to print the next two commands in the same line in the output screen.
dbms_output.put_line(j);
dbms_output.put_line(j+1);
You could do this in plain SQL instead of PL/SQL as follows:
select to_char(sum(res) over(order by res)) as res
from ( select sum(power(10, level - 1)) over(order by level) as res
from dual
connect by level <= 5 )
Result:
RES
--------------------
1
12
123
1234
12345
To_char()
function is used just to align result to the left.
To print multiple outputs on the same line, use
dbms_output.put
instead ofdbms_output.put_line
.CAVEAT When using
dbms_output.put
, you have to flush the buffer afterwards - otherwise, your output won't appear on the screen.Your original question can be solved by using two for loops: