1

I have a alhpanumeric string. I also have one number with me. The string will always start with this number. How do I separate this number from the string and get the remaining part of the string?

e.g. string => 21fgggg21.lkkk and number=> 21

result=> fgggg21.lkkk

or

string=> 215699898.55fff and number=> 2

result=> 15699898.55fff

Any hint would be appreciated. Thanks.

3 Answers 3

3
substr(string, length(number)+1)

or

regexp_replace(string, '^'||number)
Sign up to request clarification or add additional context in comments.

Comments

2

You could also use REGEXP_REPLACE. To remove '21' from the beginning of the string:

SELECT REGEXP_REPLACE('21fgggg21.lkkk', '^21') FROM DUAL;

REGEXP_REPLA
------------
fgggg21.lkkk

To remove '2' from the beginning of the string:

SELECT REGEXP_REPLACE('215699898.55fff', '^2') FROM DUAL;

REGEXP_REPLACE
--------------
15699898.55fff

By way of explanation...

  1. The caret (^) means "anchor to the beginning of the string".
  2. ^21 means "match 21 at the beginning of the string".
  3. REGEXP_REPLACE has an optional third parameter of what to replace the matched string with. Because you just want to remove the matched string you can omit the parameter, which replaces it with nothing.

2 Comments

Thank you very much for nice explanation. I will mark your answer as helpful. But I will choose Egor's answer as final once, cause he had answered it before you. Thanks again.
Appreciate it! I'm also voting up Egor's answer because, well, it's excellent - it was more targeted than mine and gave two options.
0

If you are just looking to select it, you can use a combination of substr and instr.

substr(string, instr(string, 'number') + 1, len(string))

Your result should basically be the string started after where the number is located.

1 Comment

instr(string, 'number') would always be equal to 1 as string starts with number

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.