Monday, November 23, 2009

RPAD/LPAD with NULL

Use of RPAD.

sql>Select rpad('A',5) from dual;
----------------
'A    '

But if NULL is one of the Argument then RPAD will not work.

sql> set NULL *
sql> Select rpad(NULL,5) from dual;
----------------
*

Solution:

sql> set NULL *
sql> Select rpad(NVL(NULL,' '),4) from dual;
----------------
'    '  

We will have to use NVL with rpad.


Thanks,
Soham Khot



3 comments: