A. Lemesanyi A. Lemesanyi - 1 year ago 44
SQL Question

Sql Orcle: Regexp_substr

I have the following expression:

in one of my columns.

I successfully used
SUBSTR(REGEXP_SUBSTR(base.systemdate, '.+,'), 1, 9)
to get
(expression until first comma) from the expression.

But I for hell can't figure out how to get
(the last expression after last comma).

Is there some way to use
to get that? And since we are at it.

Is there a neat way to only use
to get
without comma? Because I am using second SUBSTR to get rid of the comma, so I can get it compatible with data format.

Answer Source

You can use a very similar construct:

SELECT REGEXP_SUBSTR(base.systemdate, '[^,]$')

Oracle (and regular expressions in general) are "greedy". This means that they take the longest string. If you know the items in the list are all the same length, you could just use:

SELECT SUBSTR( ase.systemdate, -9)