Oracle - 从varchar字符串中提取时间戳? [英] Oracle - extract timestamp from varchar string?

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

问题描述

我有字符串链接:

'Podlaski Oddział Straży Granicznej 
Informacja dobowa o zdarzeniach na terenie województwa podlaskiego 
w dniu 15.04.2013 r.'

我需要从此字符串中提取日期:day: 15,month:4,year:2013并将检索到的信息放入时间戳记(6),如下所示:

I need extract date from this string: day: 15, month:4, year: 2013 and put retrieved info into timestamp(6), something like this:

to_timestamp(v_string)

..其中v_string被检索的值(在这种情况下为'13 / 04/15')

.. where v_string is retrieved value (in this case '13/04/15')

使用正则表达式做最好的方法是什么,以获得'13/04/15'作为这个例子的结果?

What is the best way to do this with regex, to get '13/04/15' as result in this example?

推荐答案

SQL> alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF';

Session altered.

SQL> with t as (
  2     select 'Podlaski Oddział Straży Granicznej
  3  Informacja dobowa o zdarzeniach na terenie województwa podlaskiego
  4  w dniu 15.04.2013 r.'
  5         as original_string
  6       from dual)
  7  select to_timestamp(regexp_substr(original_string, '\d\d\.\d\d\.\d\d\d\d'), 'DD.MM.YYYY') as the_timestamp
  8    from t;

THE_TIMESTAMP
---------------------------------------------------------------------------
2013-04-15 00:00:00,000000000

1 row selected.

这篇关于Oracle - 从varchar字符串中提取时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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