在特定文字之后查找日期(oracle)

时间:2019-08-14 21:26:06

标签: regex oracle

我正在尝试在特定字符串之后提取日期(我们现在在文本字段中将其称为IMP。它可能显示为大写/小写,并显示为IMP 1/1/10IMP happened on 1/1/10或{ {1}}

例如下面的代码-

IMP-1/1/10

会得到第一个约会,但不会得到我想要的约会- 我尝试过

SELECT REGEXP_SUBSTR('abc 3/4/16 blah blah IMP 3/7/16', '(\d{1,2}/\d{1,2}/\d{2,4})') "REGEXP_SUBSTR" from dual

和其他排列。

'(IMP) (.|(a-z){1-10}) (\d{1,2}/\d{1,2}/\d{2,4})'

如果我包含SELECT REGEXP_SUBSTR('abc 3/4/16 blah blah IMP 3/7/16', '(\d{1,2}/\d{1,2}/\d{2,4})') "REGEXP_SUBSTR" from dual ,则仅使用 (IMP) (.|(a-z){1-10})我得到了第一个出现的日期

1 个答案:

答案 0 :(得分:1)

像这样吗?

SQL> with test (id, col) as
  2    (select 1, 'abc 3/4/16 blah blah IMP 3/7/16'                     from dual union all
  3     select 2, 'abc 3/4/16 blah blah 3/7/16 imp 2/8/15 xxx cc2'      from dual union all
  4     select 3, 'xxx 3/5/18 ccdd 234 imp happened on 5/8/19 some 23f' from dual union all
  5     select 4, '3/10/18 bla bla imp-3/9/17 xfe 334 3/4/13 x'         from dual
  6    )
  7  select id,
  8    regexp_substr(substr(col, instr(lower(col), 'imp ') + 4), '\d+/\d+/\d+') result
  9  from test;

        ID RESULT
---------- --------------------
         1 3/7/16
         2 2/8/15
         3 5/8/19
         4 3/9/17

SQL>