| |
You are here: Experts > Computing/Technology > Oracle > Oracle > pl/sql
Expert: Suchitra Joshi
Date: 5/16/2008
Subject: pl/sql
Question Hi Suchitra,
Thanks in advance for considering my question
How to display the number in the format of
1
1 1
1 1 1
and
1
2 2
3 3 3
please send a pl/sql procedure program to find the result
Answer Hi Vinoth,
Here is the plsql program to find the 1st pattern.
Following is the description of the parameters -
no_lines - Number of lines in the format (1 to 12)
sep_char - Seperating char between 2 nos (space or null)
no1 to no12 - Chars to be displayed in each line (2 digit chars)
create or replace procedure temp1
(no_lines in number,
sep_char in varchar2 default ' ',
no1 in varchar2 default null,
no2 in varchar2 default null,
no3 in varchar2 default null,
no4 in varchar2 default null,
no5 in varchar2 default null,
no6 in varchar2 default null,
no7 in varchar2 default null,
no8 in varchar2 default null,
no9 in varchar2 default null,
no10 in varchar2 default null,
no11 in varchar2 default null,
no12 in varchar2 default null
) is
i integer := 1;
j integer ;
n varchar2(2) := '';
v_line varchar2(40);
begin
if no_lines not between 1 and 12 then
raise_application_error(-20001,'No of lines must be between 1 and 12');
end if;
while i <= no_lines
loop
if i = 1 then n := no1;
elsif i = 2 then n := no2;
elsif i = 3 then n := no3;
elsif i = 4 then n := no4;
elsif i = 5 then n := no5;
elsif i = 6 then n := no6;
elsif i = 7 then n := no7;
elsif i = 8 then n := no8;
elsif i = 9 then n := no9;
elsif i = 10 then n := no10;
elsif i = 11 then n := no11;
elsif i = 12 then n := no12;
end if;
j := 1;
v_line := '';
while j <= i
loop
v_line := v_line || n || sep_char;
j := j + 1;
end loop;
dbms_output.put_line(v_line);
i := i + 1;
end loop;
exception when others then
raise_application_error (-20001,'Other Error in procedure temp1');
end temp1;
So if you call procedure using
execute temp1(8,' ','1','2','3','4','5','6','7','8')
Output will be
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
The 2nd example is bit difficult. But you may try on the same lines.
Hope this helps
Regards
Suchitra
Add to this Answer
Ask a Question
|
|