简体   繁体   English

如何在Oracle中将数字转换为日期时间

[英]How to convert number as date time in oracle

I have a string as 08012016111512 where first two characters 08 is date, next two characters 01 is month, next four characters 2016 is year ,next two characters 11 is hour,next two characters 15 is minute and last two characters 12 is seconds. 我有一个字符串为08012016111512 ,其中前两个字符08是日期,后两个字符01是月,后四个字符2016是year,下两个字符11是小时,下两个字符15是分钟,后两个字符12是秒。 Suggest me how to convert above string as date time. 建议我如何将上述字符串转换为日期时间。

You need to use TO_DATE function to explicitly convert the string literal into DATE . 您需要使用TO_DATE函数将字符串文字显式转换为DATE

to_date('08012016111512', 'DDMMYYYYHH24MISS')

For example, 例如,

SQL> alter session set nls_date_format='DD-MM-YYYY HH24:MI:SS';

Session altered.

SQL> SELECT to_date('08012016111512', 'DDMMYYYYHH24MISS') my_date FROM dual;

MY_DATE
-------------------
08-01-2016 11:15:12

NOTE : The alter session statement is only to display the date in desired format. 注意:alter session语句仅以所需格式显示日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM