RKCY
RKCY

Reputation: 4135

Remove first character from string in sql plus

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.

Upvotes: 2

Views: 6420

Answers (4)

GMB
GMB

Reputation: 222432

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.

Upvotes: 1

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

Reputation: 30555

you can use SUBSTR function

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

Upvotes: 5

Himanshu
Himanshu

Reputation: 3970

  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

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269603

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.

Upvotes: 5

Related Questions