从字符串oracle提取日期 [英] Extract date from string oracle

查看:828
本文介绍了从字符串oracle提取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列中的字符串以-'伊利诺伊州芝加哥,2015年4月20日—等等这里的文字.我想从Oracle中的此字符串中提取Date部分.关于如何执行此操作的任何想法.我可以为mm/dd/yyyy找到以下内容,但不能找到长日期格式.

I have a column in which a string starts with - 'Chicago, IL, April 20, 2015 — and so on text here'. I want to extract the Date part from this string in Oracle. Any ideas on how to do this. I was able to find something for mm/dd/yyyy like below, but not for long date format.

SELECT REGEXP_SUBSTR(' the meeting will be on 8/8/2008', '[0-9]{1,}/[0-9]{1,}/[0-9]{2,}') FROM dual 

推荐答案

如果您的列值始终以'Chicago, IL, April 20, 2015 — and so on text here'开头,则可以简单地使用SUBSTR而不是REGEXP_SUBSTR

If your columns value is always start with 'Chicago, IL, April 20, 2015 — and so on text here' then you could simly use SUBSTR instead of REGEXP_SUBSTR

SELECT 
    SUBSTR(column_name
        ,INSTR(column_name, ',', 1, 2) + 1
        ,INSTR(column_name, '—') - INSTR(column_name, ',', 1, 2) - 1
    ) 
FROM 
    dual;

否则,您可以使用REGEXP_SUBSTR作为其他答案,我原来的答案是错误的@MTO评论

If not then you could use REGEXP_SUBSTR as other answer mention, my original answer is wrong as @MTO comment

这篇关于从字符串oracle提取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆