oracle_date_to_unix
create or replace function oracle_date_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_date_to_unix;
验证:
select oracle_date_to_unix(to_date('2024-09-13 14:00:00','yyyy-mm-dd hh24:mi:ss')) as date_to_second from dual
SQL> select oracle_date_to_unix(to_date('2024-09-13 14:00:00','yyyy-mm-dd hh24:mi:ss')) as date_to_second from dual;
DATE_TO_SECOND
--------------
1726207200
SQL>