选择语句以在字符串中指定日期

时间:2018-05-25 13:24:42

标签: sql oracle select

使用这样的表:

article_tbl
 ID          varchar2(500) 
 REASON      varchar2(500)
 DESCRIPTION varchar2(500)

我需要从REASON

获取日期值

根据描述,日期位置可能会有所不同。

例如:

ID |DESCRIPTION | REASON                                                                 |
------------------------------------------------------------------------------------------
1  |'DELETED'   |'THIS MESSAGE HAS BEEN DELETED ON 25/05/2018. PLEASE CHECK IN ARCHIVE.' |
2  |'AUTOREPLY' |'THIS WAS AUTOREPLY ON 25/05/2018.'                                     |
3  |'FORWARDED' |'THIS MESSAGE WAS FORWARDED ON 25/05/2015.MAILGROUP abc@outlook.com.'   |
4  |'SENT'      |'THIS MESSAGE WAS SENT TO SPECIFIC GROUP ON 25/05/2018'                 |

1 个答案:

答案 0 :(得分:4)

如果我理解并且假设reason的所有值都是您列出的格式之一,并且日期正确,则可以使用:

select regexp_substr(reason, '[0-9]{2}\/[0-9]{2}\/[0-9]{4}')
from article_tbl

这只是获取xx/xx/xxxx格式的字符串,其中x是一个数字;请注意,即使是99/45/8123之类的内容也会被提取出来。