--timestamp转为字符型
select to_char(systimestamp,'yyyy-mm-dd hh24:mi:ss.ff6') from dual;
SELECT CAST(sysdate as timestamp) from dual;
--unix时间戳与date时间互转
SELECT oracle_to_unix(SYSDATE),unix_to_oracle(1551774286),oracle_to_unix(SYSDATE) FROM dual;
--当前毫秒级时间,毫秒长度最大为6,但是只有3位有效。所以计算时都使用3位进行计算
select to_char(current_timestamp,'yyyy-mm-dd hh24:mi:ss.ff6') from dual;
--字符串转为 timestamp类型
select to_timestamp('2012-02-03 10:29:46.453234','yyyy-mm-dd hh24:mi:ss.ff6') from dual;
--timestamp转为字符型
select to_char(systimestamp,'yyyy-mm-dd hh24:mi:ss.ff6') from dual;
--当前毫秒级时间
select to_char(current_timestamp,'yyyy-mm-dd hh24:mi:ss.ff6') from dual;
select current_timestamp from dual;
SELECT (SYSDATE - TO_DATE('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')) *
86400000 + TO_NUMBER(TO_CHAR(SYSTIMESTAMP(6), 'FF')) AS MILLIONS,
SYSDATE,
TO_NUMBER(TO_CHAR(SYSTIMESTAMP(6), 'FF')),
(SYSDATE - TO_DATE('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')) *
86400000
FROM DUAL;
--当前时间转毫秒数(2019/3/5 15:53:41)->(1551801221228)
SELECT (SYSDATE - TO_DATE('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')) *
86400000 + TO_NUMBER(TO_CHAR(SYSTIMESTAMP(3), 'FF')) AS MILLIONS,
SYSDATE
FROM DUAL;
--毫秒数转时间(1551801221228)->(2019-03-05 15:52:55.576)
SELECT MILLISECONDS2TIMESTAMP(1551774330) FROM DUAL;
SELECT TO_CHAR(MILLISECONDS2TIMESTAMP(1551804255181),
'yyyy-mm-dd hh24:mi:ss.ff3')
FROM DUAL;
--毫秒数转时间(1551801221228)->(2019/3/5 15:52:56)
select num_to_date(1551804255181) from dual;
SELECT TO_CHAR(1551804255181 / (1000 * 60 * 60 * 24) +
TO_DATE('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS') AS CDATE,
to_timestamp(TO_CHAR(1551804255181 / (1000 * 60 * 60 * 24) +
TO_DATE('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS'),'yyyy-mm-dd hh24:mi:ss.ff3') AS to_timestamp,
to_char(to_timestamp(TO_CHAR(1551804255181 / (1000 * 60 * 60 * 24) +
TO_DATE('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS'),'yyyy-mm-dd hh24:mi:ss.ff3'),'yyyy-mm-dd hh24:mi:ss.ff3') AS to_char1,
TO_CHAR(MILLISECONDS2TIMESTAMP(1551804255181),
'yyyy-mm-dd hh24:mi:ss.ff3') AS to_char
FROM dual t;
函数下载地址:
https://download.csdn.net/download/qinshihuanglove2/10997979
https://download.csdn.net/download/qinshihuanglove2/10997973
oracle中日期类型与unix 时间戳的转换
https://download.csdn.net/download/qinshihuanglove2/10998008