简体   繁体   中英

how to extract date from string in sql oracle 9i

I have column Explanation (VARCHAR2) in table:

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 

I need query thats will answer "Does entry have a date in some form in it?" Yes / No for each entry. Is it possible on Oracle 9i?

I tried some solutions. But run into issue:

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

I don't clearly now where datestamp will be in field.

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

You can do this using regular expression. Try below code :

  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;

Output :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM