Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to use rpad but it does not display why

Status
Not open for further replies.

csphard

Programmer
Apr 5, 2002
194
US
select rpad(mname,20) || rpad(mtype,20) || state from
(select 'Mickey Mouse' as mname, 'President' as mtype, 'California' as state from dual)

This comes out like Mickey Mouse President California.

Why did'nt I get my right paddings

Howard

 
Here is my problem. I am displaying first and last name with the title to the right. I would like the title to line up on the right.
Another example. I hope this one is better

select rpad(mname,20) || rpad(mtype,20) || state from
(select 'Mickey Mouse' as mname, 'Mouse' as mtype, 'California' as state from dual
union
select 'Donald Duck' as mname, 'Duck' as mtype, 'California' as state from dual
union
select 'Bugs Bunny' as mname, 'Rabit' as mtype, 'California' as state from dual
)

I want to have type line up I want the state to line up.
I thought that by putting in the padding it would pad them all to that lenght.
Meaning Bugs Bunny is 11 characteres so it would pad 9 more spaces.
Donald Duck is 10 characteres so it would pad 10 more spaces.

That way the type would line up. and the same with padding the mtype
Rabit is 3 characters to it would add 17.

How can I get this to happen?
 
csphard said:
I would like the title to line up on the right
I presume by this you want "text right alignment" to occur. For that, you want to use Oracle "LPAD()" function:
Code:
select lpad(mname,20) || lpad(mtype,20) || state from 
(select 'Mickey Mouse' as mname, 'Mouse' as mtype, 'California' as state from dual
union
select 'Donald Duck' as mname, 'Duck' as mtype, 'California' as state from dual
union
select 'Bugs Bunny' as mname, 'Rabit' as mtype, 'California' as state from dual
);

LPAD(MNAME,20)||LPAD(MTYPE,20)||STATE
--------------------------------------------------
          Bugs Bunny               RabitCalifornia
         Donald Duck                DuckCalifornia
        Mickey Mouse               MouseCalifornia
Let us know if this is what you wanted.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
a mickey mouse solution, if ever I saw one!

Regards

T
 
What a "Goofy" thing to say. If I said, "It 'Bugs' me," I'd be lying, so I'll "Duck" the issue. <grin>

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top