Regular Expressions

From dbawiki
Revision as of 14:35, 12 February 2013 by Stuart (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Oracle can do almost as much as Perl but it's not quite there yet!

Select a piece out of a long filename:

string := '/oracle/export/MOCMMSP2/expdp_DEV2_D_FULL_20130131210003_01.dmp.gz';

SELECT REGEXP_SUBSTR(
,      string,
,      '(\_)([0-9]+)(\_)'   --<-- expression with subexpressions
,      1                    --<-- starting position
,      1                    --<-- nth occurrence
,      'i'                  --<-- match parameter (ignore case)
,      2                    --<-- 11g: subexpression to return
,      )
FROM   dual

This will pick out the date part of the filename.

References[edit]

[oracle-developer.net]