counteragent0090 counteragent0090 - 3 days ago 4x
SQL Question

Need to extract a string from a filename

I have a column in a staging table where i am inserting the filenames. The format for the filename is as follows:

T225674_<suppliercode><YYYYMMDD>-<HHMM>_**<TIMBE NUMBER>**.in


(I need to extract 12345 from the above string, the string can be anything and of whatever length)

I need to extract
from the above filename, could you please let us know how to do it in Oracle SQL.



I'm sure there's a regexp that does this but that's not my strongest point. However, a combination of instr and substr will get you there:

substr(string, instr(string, '_', -1) + 1, instr(string, '.') - instr(string, '_', -1) - 1))