AllExperts > Experts 
Search      

Oracle

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Oracle Answers
Question Library

Ask a question about Oracle
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Suchitra Joshi
Expertise
I can answer questions regarding SQL, PL/SQL, Procedures, Functions, Triggers, SQL Loader and some basic dba activities or performance tuning for Oracle 8i database. I cannot answer questions related to major dba activities, backup and recovery.

Experience
10+ years
D2K

Awards and Honors
OCP - SQL and PL/SQL
Brainbench certifications in Oracle Administration, Database, PL/SQL

 
   

You are here:  Experts > Computing/Technology > Oracle > Oracle > pl/sql

Topic: Oracle



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



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.