Oracle时间戳 与时间之间的相互转换

 Unix时间戳记是从'1970-01-01 00:00:00'GMT开始的秒数,表现为整数型。

  Oracle中的时间是Date型,以下函数提供了两种时间转换的Oracle函数

 (1)从Unix时间戳记转换为Oracle时间

  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;

 (2)由Oracle时间Date型转换为Unix时间戳记

  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;

原文地址:https://www.cnblogs.com/Brainpan/p/4366212.html