2

I'm new to Oracle and not sure how to remove the first character in the String.

For example this value

,1,2,3,4,5,6,7

Here I loop it and appending comma after each value. But unfortunately first time it is appending comma. Not sure how to remove it.

1
  • this is almost certainly a bad problem. you should change how you are normalizing and not ever need to parse lists of numbers in a column Commented Dec 24, 2018 at 18:21

4 Answers 4

5

One method is to use ltrim():

select ltrim(<string>, ',')

I am suspicious whenever I see numbers like that in a string. That is not a good way to represent lists of numbers.

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

Comments

5

you can use SUBSTR function

select substr(',1,2,3,4,5', 2) from dual

Comments

1

You can be a little more specific using a regexp that removes the first character only if it is a comma.

In oracle :

SELECT REGEXP_REPLACE( 
    ',1,2,3,4,5',
    '^,',
    ''
) FROM DUAL;

Regexp explanation : ^ denotes the beginning of the string, followed by the comma. If the string matches, the matched part is replaced with the empty string.

Comments

0
  Ltrim(<string>,'charecter')  
   ----to left trim charecters (left side of the string)
  ,Rtrim(<string>,'charecter')
       ---to right trim charecters (right side of the string)

For your query you require

       select Ltrim(<string>,',') from table

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.