Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
cancel
Showing results for 
Search instead for 
Did you mean: 

Help with RPAD.

Raj_38
Occasional Advisor

Help with RPAD.

While spooling I'm trying to RPAD a column like ,

RPAD(cell_id,10,' ')

If cell_id = 'AB' , then its RPADing with 8 spaces to right. But if cell_id is completely NULL , nothing is been added . I mean it return nothing.I tried the following too,

RPAD(NVL(cell_id,' '),10,' ')

Even this doesnt help.

Any thoughts / Help ?
8 REPLIES
Yogeeraj_1
Honored Contributor

Re: Help with RPAD.

hi,
-
I don't have a database at hand to test it right now...
-
can you try replacing '' with chr(0)
i.e.
rpad(cell_id,10,chr(0))
-
revert
-
regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Raj_38
Occasional Advisor

Re: Help with RPAD.

Nope..Even that doesnt help.

Yogeeraj_1
Honored Contributor

Re: Help with RPAD.

RPAD(NVL(cell_id, ' '), 10, ' ')

with a space between the single quotes...

does this help?

can't help any further till i get back to my books and db....

regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: Help with RPAD.

hi again,
-
did you know that:
A ZERO length varchar is treated as NULL.
-
'' is not treated as NULL.
-
-
'' when assigned to a char(1) becomes ' ' (char types are blank padded strings).
-
-
'' when assigned to a varchar2(1) becomes '' which is a zero length string and a zero length string is NULL in Oracle (it is no long '')
-
regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Raj_38
Occasional Advisor

Re: Help with RPAD.

Yes. I have specified a space between ' '.
but its not working.

My requirement is in spool file there should be 10 blank space if the cell id is NULL.
any method is ok for me.
Brian Crabtree
Honored Contributor

Re: Help with RPAD.

How about:
nvl(rpad(cell_id,' '),' ');

Thanks,

brian

Indira Aramandla
Honored Contributor

Re: Help with RPAD.

Hi Raj,

What you were doing was correct.

Your command RPAD(NVL(cell_id,''),10,'') works as you want it if you gave space between the single quotes.

Here is an example I tried. Instead of space I gave '*' so that you can see.

The table has ename of varchar2(10) and has the value 'aaa', 'ccc', null and spaces for the four records.

Select eno, ename from tab1.
101 aaa
102 ccc
103
104

Now I want the ename to be filled with '*' for the reamining 7 spaces, including the columns that are null and spaces.

SQL> select eno, rpad(nvl(ename,' '),10,'*') from tab1;

ENO RPAD(NVL(E
---------- ----------
101 aaa*******
102 ccc*******
102 *********
102 *********

I hope this helps.

IA
Never give up, Keep Trying
Yogeeraj_1
Honored Contributor

Re: Help with RPAD.

Hi again,
*
As IA showed above, it works!
see below: (please replace '_' with
*
yd@MYDB.MU> create table ydtab (cell_id varchar2(10));
*
Table created.
*
Elapsed: 00:00:00.40
yd@MYDB.MU> insert into ydtab values(null);
*
1 row created.
*
Elapsed: 00:00:00.00
yd@MYDB.MU> commit;
*
Commit complete.
*
Elapsed: 00:00:00.01
yd@MYDB.MU> select '|'||rpad(cell_id,10,'_')||'|' from ydtab;
*
'|'||RPAD(CE
____________
||
*
Elapsed: 00:00:00.00
yd@MYDB.MU> select '|'||rpad(nvl(cell_id,'_'),10,'_')||'|' from ydtab;
*
'|'||RPAD(NV
____________
|__________|
*
Elapsed: 00:00:00.00
yd@MYDB.MU>
*
regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)