1:整数到时间的转换:
create or replace function inttotime(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 inttotime;
使用:
select inttotime(1420795820) from dual;
结果:
2015/1/9 17:30:20
2:时间到整数的转换:
create or replace function timetoint(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 timetoint;
使用:
select timetoint(to_date('2015/1/9 17:30:20','yyyy/mm/dd hh24:mi:ss')) from dual;
结果:
1420795820
本文介绍在Oracle数据库中如何实现时间与整数之间的相互转换。提供了两个自定义函数,inttotime用于将整数转换为日期时间,timetoint用于将日期时间转换为整数。整数表示的是从1970年1月1日0时起的秒数,适用于Unix时间戳的处理。
321

被折叠的 条评论
为什么被折叠?



