如何从 sql oracle 9i 中的字符串中提取日期

how to extract date from string in sql oracle 9i

我在 table 中有列解释 (VARCHAR2):

No| Explanation  
1 | Shipment of cabbage by agreement 29.04.2019 TAX Free  
2 | Payment for screws (01.04.19) Tax: 13.55 %  
3 | For reserch by deal dated 01.01.2015 Tax free  
4 | Tax payment for the may 2019 

我需要查询,每个条目都会回答 "Does entry have a date in some form in it?" 是/否。在 Oracle 9i 上可以吗?

我尝试了一些解决方案。但是 运行 问题:

"ORA-01858: a non-numeric character was found where a numeric was expected".

我现在不清楚日期戳在字段中的什么位置。

select to_char(to_date(EXPLANATION, 'DD.MM.YYYY')) from PAYMENTDOC

您可以使用正则表达式来做到这一点。试试下面的代码:

  select No, Explanation, 
  case when regexp_instr(Explanation,'\d{2}.\d{2}.\d{2}')!=1 then 
              'Y'
              when regexp_instr(Explanation,'\d{2}.\d{2}.\d{4}')!=1 then
              'Y'
              when REGEXP_instr(Explanation, '(January|February|March|April|May|June|July|August|September|October|November|December) [0-9]{4}')!=1 then
              'Y'
             END Does_entry_have_a_date_in_some_form_in_it
  from table_name;

输出:

No| Explanation                                          | Does_entry_have_a_date_in_some_form_in_it
1 | Shipment of cabbage by agreement 29.04.2019 TAX Free | Y
2 | Payment for screws (01.04.19) Tax: 13.55 %           | Y
3 | For reserch by deal dated 01.01.2015 Tax free        | Y
4 | Tax payment for the may 2019                         | Y