Search code examples
sqloracle-databaseplsqlprintform

i need to print numbers in pl sql in the given format?


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);

Solution

  • To print multiple outputs on the same line, use dbms_output.put instead of dbms_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:

    begin
      for i in 1 .. 10
      loop
        for j in 1 .. i
        loop
          dbms_output.put(to_char(j) || ' ');
        end loop;
        dbms_output.new_line;
      end loop;
    end;