簡體   English   中英

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

[英]how to extract date from string in sql oracle 9i

我在表中有列說明(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 

我需要查詢,它會回答“條目是否有某種形式的日期?” 每個條目都是/否。 是否可以在Oracle 9i上使用?

我試過一些解決方案。 但遇到問題:

“ORA-01858:在預期數字的位置找到了非數字字符”。

我現在還不清楚datestamp將在哪個字段中。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM