0

I'd like to extract the number between NUMBER and ;. So far I can extract the data up to the number, but I don't want anything after the number. e.g.,

SELECT
    SUBSTRING(field, LOCATE('NUMBER=', rrule) + 7)
FROM table

Data field:

DATA:PASS=X12;NUMBER=331;FIELD=1
DATA:PASS=X12;NUMBER=2;FOO=BAR;FIELD=1

Desired Output:

331
2

1 Answer 1

3

You can use a combination of SUBSTRING_INDEX functions:

SELECT
  SUBSTRING_INDEX(
    SUBSTRING_INDEX(field, 'NUMBER=', -1),
    ';',
  1)
FROM
  tablename

Please see an example fiddle here.

The inner SUBSTRING_INDEX will return everything after the NUMBER= string, while the second will return everything before the ; returned by the inner function.

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

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.