Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to lpad zeroes for a number field?

993017Feb 20 2014 — edited Feb 21 2014

Hi ,

I try to use lpad function to add zeroes a number field but it does not work. It only works numbers except '0'. I run this queries on 11gr2 and 10gr2 but get same results.

lpad function is for characters but Is there any way to do it?

Here my examples;

SQL> create table samp_tab (id number);

Table created.

SQL> insert into samp_tab (id) values (lpad('123',9,'0'));

1 row created.

SQL> select * from samp_tab;

        ID

----------

       123

----- I've tried to lead another number and it works well

SQL> insert into samp_tab (id) values (lpad('123',9,'5'));

1 row created.

SQL> select * from samp_tab;

        ID

----------

       123

555555123

SQL> insert into samp_tab (id) values (lpad('123',9,'8'));

1 row created.

SQL> select * from samp_tab;

        ID

----------

       123

555555123

888888123

-- I 've tried without quotes:

SQL> insert into samp_tab (id) values (lpad('123',9,0));

1 row created.

SQL> select * from samp_tab;

        ID

----------

       123

555555123

888888123

       123

-- rpad functions works well.

SQL> insert into samp_tab (id) values (rpad('123',9,0));

1 row created.

SQL> select * from samp_tab;

        ID

----------

       123

555555123

888888123

       123

123000000

SQL>

Any help appreciated

Regards.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 21 2014
Added on Feb 20 2014
10 comments
10,175 views