Results 1 to 4 of 4

Thread: I would like to lpad the first 10 numbers

  1. #1
    Geek_Guest
    Guest

    I would like to lpad the first 10 numbers

    I have a table which holds both negative and positive integers for a particular column and the column can accomodate any no. of integers.

    I would like to lpad the first 10 numbers.
    I can get my expected result for the positive integer.
    But for the negative integer, I will get my result has '****-12345', if used lpad(dno,10,'*')
    which is not the expected output.
    The o/p should be similar to '-****12345'.
    How can I achieve it.

    Thanks in advance.
    Question asked by visitor karthick


  2. #2
    Junior Member
    Join Date
    Jun 2007
    Answers
    9

    Re: I would like to lpad the first 10 numbers

    Hi, you can use a case expression in this problem,

    /* Oracle DB */

    select case when dno < 0 then '-' || lpad(dno,9,'*')
    else lpad(dno,10,'*')
    end
    from dual

    On other RDBMS I don't know if case expression are supported but I think that case expressions are part of the SQL92 standar.

    HTH


  3. #3

    Re: I would like to lpad the first 10 numbers

    Try this dear it will work fine:-

    select replace(dno,substr(dno,2,10),'**********') from dept


  4. #4

    Re: I would like to lpad the first 10 numbers

    Try this dear it will work fine:-

    select replace(dno,substr(dno,2,10),'**********') from dept


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact