0

It may be very simple question, but I have run out of ideas. I would like to remove first 5 characters from string.

Example string will look like: 1Y40K100R

I would like to display only digits that are after '%K' which in this case should give me result of 100R. Please note that number after 'K' can have different amount of digits. It can be 4 digit number or 2 digit number.

1
  • You are contradicting yourself is such a short space - this must be a record! Do you want to remove the first five characters regardless of what they are, or do you want to remove everything up to and including K? (If there is more than one K, which K? The first one? the last one?) Or is the fifth character always K, and you must remove the first five characters in call cases? Commented Feb 6, 2018 at 18:59

2 Answers 2

3

Just use substr():

select substr(col, 6)

This returns all characters starting at the sixth.

There are multiple ways to return all characters after the k. If you know the string has a k, then use instr():

select substr(col, instr(col, 'K') + 1)
Sign up to request clarification or add additional context in comments.

Comments

0

You can use regexp_substr

select regexp_substr('1Y40K100R', '(K)(.*)', 1, 1, 'i', 2) from dual

A way without regexp:

select substr('1Y40K100R', instr('1Y40K100R', 'K') +1) from dual

This may appear not so elegant, but it usually performs better than the regexp way.

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.