1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

How to convert a input to default digit value.,?!

Discussion in 'SQL PL/SQL' started by Vicky, May 20, 2014.

  1. Vicky

    Vicky Forum Advisor

    Messages:
    261
    Likes Received:
    11
    Trophy Points:
    260
    Location:
    Chennai
    Can any one tell me, How to convert an input to default digit value.,?! Is der any predefined function for appending length.,?!

    Eg: Lets take 6 as the default digit value., If I give input as 12 means the the o/p should come as 000012.,

    Thnx.,
     
  2. rajenb

    rajenb Forum Expert

    Messages:
    361
    Likes Received:
    114
    Trophy Points:
    655
    Location:
    Mauritius
    Hi Vicky,
    Try this:
    SELECT lpad('12',6,'0') from dual;

    Regards,
    Rajen.
     
    jagadekara and Vicky like this.
  3. Vicky

    Vicky Forum Advisor

    Messages:
    261
    Likes Received:
    11
    Trophy Points:
    260
    Location:
    Chennai
    Tanq Rajen.,.
     
  4. ocprep

    ocprep Forum Advisor

    Messages:
    277
    Likes Received:
    76
    Trophy Points:
    410
    Location:
    Orlando, Florida
    LPAD is a character function. Strictly speaking, the number format model 000009 should be used.
    That said, since Oracle has to convert the number to character data to display it, the difference is minimal:

    Code (Text):
    SELECT TO_CHAR(12, '000009')
    FROM   dual;

    TO_CHAR(12,'000009')
    ---------------------
     000012  
     
    Vicky and jagadekara like this.