[英]Convert unix time format to date/time format in oracle sql
I have a column called data_time (varchar) and there are about 200 thousand rows. 我有一个名为data_time(varchar)的列,大约有20万行。 I would like to convert those rows to ordinary date/time instead. 我想将这些行转换为普通日期/时间。
I have tried this with no luck. 我试过这个没有运气。
example value in a row: 927691200000000 行中的示例值:927691200000000
SELECT * TO_DATE('19700101',yyyymmdd') + ((date_time/1000)/24/60/60) thedate 2 FROM table1
I am new to SQL and help is appreciated! 我是SQL的新手,非常感谢!
Thank you. 谢谢。
I cleaned up the obvious syntax errors, added some date formatting, and just hardcoded the one sample value you provided, thus: 我清理了明显的语法错误,添加了一些日期格式,只是硬编码了你提供的一个样本值,因此:
SELECT to_char(TO_DATE('19700101','yyyymmdd') + ((927691200000000/1000)/24/60/60),'DD-MON-YYYY') thedate FROM dual;
And that yielded: 这产生了:
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
Which suggests that your unix time is (probably?) expressed in microseconds, not milliseconds. 这表明你的unix时间(可能是?)以微秒表示,而不是毫秒。
So, I modified the query thus: 所以,我修改了查询:
SELECT to_char(TO_DATE('19700101','yyyymmdd') + ((927691200000000/1000000)/24/60/60),'DD-MON-YYYY') thedate FROM dual;
Which returns: 哪个回报:
THEDATE
-----------
26-MAY-1999
Which I assume to be correct? 我认为哪个是正确的?
Hope that helps.... 希望有所帮助....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.