1

I am trying to create a dump file from within SQL*Plus. The requirement is to create null '' for padding but when I use NULL even the data value is getting nullified see below.

SQL> select RPAD(1234,10,' ') from dual ;

RPAD(1234,
----------
1234

SQL> select RPAD(1234,10,'') from dual;

R
-

I have seen other scripts where they seem to be using null('') for padding

Please help thanks

3
  • 3
    What exactly are you trying to do? What sense does it make to pad a value with "nothing"? Commented Sep 11, 2013 at 21:55
  • 1
    NULL and empty string are not the same. It makes no sense to pad with either of them. Usually single space is used for padding. Are you possibly mistaking '' for ' '? Commented Sep 11, 2013 at 22:22
  • 3
    @PM77-1 in oracle null and empty string ARE the same :) try select * from dual where '' is null; Commented Sep 12, 2013 at 4:23

2 Answers 2

4

RPAD accepts a character or string as its 3rd parameter which is used to "pad" the initial string to a particular length.

RPAD can be used to return a string which is "guaranteed" to be n characters long (as per the 2nd parameter).

Since NULL does not represent any particular character or string and has zero length, it cannot be used for padding - RPAD apparently returns NULL in this instance, which makes sense as the only other option would be for RPAD to raise an exception.

Sign up to request clarification or add additional context in comments.

2 Comments

Yep. “RPAD(expr1 , n [, expr2 ])… expr1 cannot be null.” Reference
@javaPlease42, yes - but the OP was talking about expr2, which can be null (although not very useful if used that way).
-1

This code:

RPAD(1234,10,'')

concatenates 1234 to '', which in Oracle is equivalent to NULL, therefore it results in NULL (anything concatenated to NULL yields NULL)

There is no NULL('') in Oracle.

Hope that helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.