Oracle to_date function. Mask needed

旧城冷巷雨未停 提交于 2019-12-01 17:19:36
select TO_DATE('2010-09-09T22:33:44.OZ'
              ,'YYYY-MM-DD"T"HH24:MI:SS".OZ"')
from dual;

9/09/2010 10:33:44 PM

If the timezone information is needed:

select to_timestamp_tz('2010-09-09T22:33:44.GMT','YYYY-MM-DD"T"HH24:MI:SS.TZR')
from dual;

09-SEP-10 22.33.44.000000000 GMT

But OZ isn't a recognised timezone abbreviation, so you'd need to do some pre-conversion of that to something that is.

If you want to just ignore that part, and it's fixed, you can do what @Jeffrey Kemp said:

select to_date('2010-09-09T22:33:44.OZ','YYYY-MM-DD"T"HH24:MI:SS."OZ"')
from dual;

09/09/2010 22:33:44 -- assuming your NLS_DATE_FORMAT is DD/MM/YYYY HH24:MI:SS

If you want to ignore it but it isn't fixed then you'll need to trim it off first, something like (using a bind variable here for brevity):

var input varchar2(32);
exec :input := '2010-09-09T22:33:44.OZ';
select to_date(substr(:input,1,instr(:input,'.') - 1),'YYYY-MM-DD"T"HH24:MI:SS')
from dual;

09/09/2010 22:33:44
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!