Skip to main content
Question

need SQL select REGEXP that extracts the string of numbers between string [run_id] and [/run_id]

  • Jul 21, 2021 7:54 PM UTC
  • 4 replies
  • 17 views

enniwesw

need SQL select REGEXP that extracts the string of numbers between string and

field_name
37608897
12906044
21163375
8164799
11828737
20941947
1846072
32051061
31531882
37497724

The result should be.

field_name
37608897
12906044
21163375
8164799
11828737
20941947
1846072
32051061
31531882
37497724

4 replies

enniwesw
  • Author
  • New Participant
  • Jul 21, 2021 8:12 PM UTC


SruthiA
Forum|alt.badge.img+1
  • Participating Frequently
  • Jul 21, 2021 10:41 PM UTC

@enniwesw Please find the solution below

dbadmin=> select substring (text, instr(text, '')+length('') , instr(text, '')-(instr(text,'')+length(''))) from test_str;

substring

1546776
15423476568
3476568
3476
(4 rows)

dbadmin=>


SergeB
Forum|alt.badge.img
  • Participating Frequently
  • Jul 22, 2021 12:33 AM UTC

In your example, the following might be sufficient as there is only one number to grep.

select regexp_substr(text,'\d+') from test_str;

Of if you wanted to grep the numbers between the run_id tags

select regexp_substr(text,'<run_id>(\d+)</run_id>',1,1,'',1) from ztest_str;


enniwesw
  • Author
  • New Participant
  • Jul 22, 2021 6:33 AM UTC

@SergeB , many thanks, the query greping the numbers between the run_id tags works magic!

select regexp_substr(text,'(\d+)',1,1,'',1) from ztest_str;