oracle unix时间戳与date转换

时间:2017-11-01 18:48:43   收藏:0   阅读:920

  

linux 时间戳 转date:
 
创建自定义函数:
create or replace function unix_to_oracle(in_number number) return date is
begin
  return (to_date(19700101,yyyymmdd) + in_number/86400
  + to_number(substr(tz_offset(sessiontimezone),1,3))/24);
 
end unix_to_oracle;

 

 使用:
select unix_to_oracle(1509490525) from dual;

技术分享

 

 
 
date 转linux时间戳:
 
create or replace function oracle_to_unix(in_date in date) return number is
begin
  return ((in_date-to_date(19700101,yyyymmdd))*86400 -
  to_number(substr(tz_offset(sessiontimezone),1,3))*3600);
  end oracle_to_unix;

 

 使用:
select oracle_to_unix(sysdate) from dual;

技术分享

原文:http://www.cnblogs.com/Springmoon-venn/p/7767779.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!