Home > OS >  How to match second group of digit in a alphanumeric string
How to match second group of digit in a alphanumeric string

Time:04-09

I'm trying to query for both the first and the second group of digits of a string on a MySQL table but after some attempts I only got the first group of digits to match and a copy of it as "the second group".

The query I used:

SELECT DISTINCT rif,REGEXP_SUBSTR(rif,"[0-9] ") AS num1, REGEXP_SUBSTR(rif, "[0-9] ") AS num2 FROM "table" WHERE rif LIKE " 5 QUEEN%"

And here is the output it returns:

rif num1 num2
205 QUEEN-1012-K 205 205
205 QUEEN-711-K 205 205
205 QUEEN-905-K 205 205

Desired output:

rif num1 num2
205 QUEEN-1012-K 205 1012
205 QUEEN-711-K 205 711
205 QUEEN-905-K 205 905

How can I alter the query for it to return the desired output? Thanks in advance.

CodePudding user response:

The function needs additional parameters

REGEXP_SUBSTR(rif, "[0-9] ",1,2) as num2
  • Related