Oracle SQL query for a substring

I'm on an Oracle 12c database;
I have a column of data with values resembling this: HL7_Result_for_Message_ID_123Q324343.hl7

I need to grab that ID number (in bold), the challenge being that it can be any and all lengths. I have IDs that are as short as 1234, and some 25 characters, alphanumeric.

I tried a combo of rtrims and ltrims, which almost worked until i realized they don't actually match on strings, which misses some of the rows.

From what I've been able to gather, using REGEXP_SUBSTR could be a way to go, but I just don't know Regular expressions well enough to do anything useful.

Any thoughts?

Thanks
 

tiosteven

Ars Tribunus Militum
1,743
Hrm, looking at the Oracle docs I'm not sure how you output just the capture group off the top of my head.
Without regex you would use substr(string,start_pos,substring_length) which can be irritatingly verbose, let me tell you. If JohnTitor used an inline view, something like:
substr(payload_name,start_pos,end_pos-start_pos+1), mind your off-by-ones. Otherwise use the instr functions and light a candle for anyone who needs to maintain the code in three years, including youself.

As always, test it. Substr and instr are frustratingly limited but well defined. Regex specs can differ. Random syntax test sites from Google might not match Oracle’s implementation, which may change between versions.