PL/SQL Program to Print Patterns

Here you will get plsql programs to print patterns of stars, numbers and alphabets.

Pattern 1:

Pattern 2:

Pattern 3:

Pattern 4:

Pattern 5:

Pattern 6:

Pattern 7:

Comment below if you need any other pattern. I will try to add it here.

26 thoughts on “PL/SQL Program to Print Patterns

    1. akash ithape

      declare
      n number:=5;
      i number;
      j number;
      begin
      for i in 1..n
      loop
      for j in 1..i
      loop
      dbms_output.put(‘1’);
      end loop;

      dbms_output.new_line;
      end loop;
      end;
      /

      Reply
        1. ddl

          declare
          n number:=5;
          i number;
          j number;
          begin
          for i in 1..n
          loop
          for j in 1..i
          loop
          dbms_output.put(‘J’);
          end loop;
          dbms_output.new_line;
          end loop;
          end;
          /

          Reply
    2. Amol

      Declare
      n number(1);=5:
      i nimber(1):
      j number (1):
      Begin
      For i in 1..n
      loop
      for j in j..i
      loop
      dbms_output.put(j):
      end loop:
      dbms_output.new_line:
      end loop:
      End:
      /

      Reply
    3. bhargav

      declare
      n number:=5;
      i number;
      j NUMBER := 1;
      begin
      FOR k IN 1..n LOOP
      i:=i||j;
      j:=j+1;
      dbms_output.put_line(i);
      END LOOP;
      END;

      Reply
    4. siddharh

      declare
      i number;

      k number;
      n number:=4;
      begin
      for i in 1..n
      loop

      k:=1;
      while k<i+1
      loop
      dbms_output.put(k);
      k:=k+1;
      end loop;

      dbms_output.new_line;
      end loop;
      end;

      Reply
    1. binod kumar

      declare
      n number:=3;
      i number ;
      k number :=0;
      j number ;
      begin
      for i in 1..n
      loop
      for j in 1..n
      loop
      dbms_output.put(j+k);
      end loop;
      dbms_output.new_line;
      k:=k+3;
      end loop;
      end;

      Reply
  1. ravi

    pl/sql is not able to add space
    declare
    n number:=10;
    i number:=1;
    j number;
    k number;
    begin
    while i<n
    loop
    j:=1;
    while j=1
    loop
    j:=9;
    while j>i
    loop
    dbms_output.put(‘ ‘);
    j:=j-2;
    end loop;

    for k in 1..i
    loop
    dbms_output.put(‘*’);
    end loop;

    dbms_output.new_line;
    i:=i-2;
    end loop;
    end;
    /

    Reply
  2. SUMA

    IF AM GIVING INPUT AS 1 THEN I NEED TO GET OUTPUT AS 1,IF INPUT IS 2 THEN OUTPUT SHOULD BE AS 2
    2 2
    IF INPUT IS 3 THEN OUTPUT SHOULD BE 3
    3 3
    3 3 3

    Reply
    1. Divya Gupta

      DECLARE
      I NUMBER;
      J NUMBER;
      BEGIN
      FOR I IN 1..5
      LOOP
      FOR J IN 1..I
      LOOP
      DBMS_OUTPUT.PUT(‘* ‘);
      END LOOP;
      DBMS_OUTPUT.NEW_LINE;
      END LOOP;
      END;

      Reply
  3. Sonu

    Hello!
    How to Write a PL/SQL program to print the following series using nested for loop.
    0 0 0 0 0
    1 2 3 4 5
    2 4 6 8 10
    3 6 9 12 15
    4 8 12 16 20
    5 10 15 20 25

    Reply
    1. Mohammed Almansour

      Solve Pattern program is

      Declare
      K number;
      I number;
      J number;
      Begin
      For i in 0..5 loop
      K := i ;
      For j in 0..5 loop
      Dbms_output.put_line ( K ) ;
      K:=K+i ;
      End loop;
      Dbms_output.new_line;
      End loop;
      End;

      Reply
    2. sriharirao

      /* 1 2 3 4 5
      2 4 6 8 10
      3 6 9 12 15
      4 8 12 16 20
      5 10 15 20 25 */

      DECLARE
      V VARCHAR2(20);
      K VARCHAR2(10);
      L VARCHAR2(10):=0;
      BEGIN
      FOR I IN 1..5 LOOP
      K:=I;
      FOR J IN 1..5 LOOP
      L:=K*J;
      V:=V||’ ‘||L;
      END LOOP;
      DBMS_OUTPUT.PUT_LINE(V);
      V:=NULL;
      END LOOP;
      END;
      /

      Reply
  4. Shwetha

    Hi, great work!! thanks for all this info here. Could you also tell us how to print just the diagonals of a square?

    Reply
  5. Mouni

    Hlo, can you write code for the below pattern
    15,14,13,12,11
    10, 9, 8, 7
    6, 5, 4
    3, 2
    1

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *