美文网首页
为oracle增加from_unixtime函数

为oracle增加from_unixtime函数

作者: 徐利华的一点空间 | 来源:发表于2021-05-06 19:30 被阅读0次

因项目需要,要使原本是php+mysql的项目支持oracle,为使项目同时支持mysql和oracle,尽量使用双方兼容的写法。

今天发现oracle中没有mysql的from_unixtime函数,所以写的一个

create or replace function from_unixtime(in_number number) return varchar2 is
begin
return to_char((to_date('19700101','yyyymmdd') + in_number/86400 + to_number(substr(tz_offset(sessiontimezone),1,3))/24),'yyyy-mm-dd hh24:mi:ss');
end from_unixtime;

这样oracle和mysql就可以兼容sql语句中from_unixtime(timestamp)的写法了~

相关文章

网友评论

      本文标题:为oracle增加from_unixtime函数

      本文链接:https://www.haomeiwen.com/subject/runddltx.html