날짜를 유닉스 타임 스탬프로 변환하는 함수를 작성했습니다. 이 함수는 현재 DST 상태 (예 : EST 또는 EDT)와 상관없이 작동하도록 작성되었습니다. 이 함수는 다음과 같습니다.mod_plsql을 사용할 때 표준 시간대 정보를 가져올 수 없습니까?
function unix_time_from_date(in_date in date) return number
as
ut number := 0;
tz varchar2(8) := '';
begin
-- Get the local timezone from the passed in date
-- Assuming the date supplied is for the local time zone
select
extract(
timezone_abbr from cast(in_date as timestamp with local time zone)
)
into tz
from dual;
-- Get the Unix timestamp
select
(new_time(in_date, tz, 'GMT') - to_date('01-JAN-1970', 'DD-MM-YYYY')) * (
86400)
into ut
from dual;
return ut;
end unix_time_from_date;
이 함수는 JDeveloper와 같은 클라이언트에서 실행할 때 유용합니다. 클라이언트가 첫 번째 쿼리에 표준 시간대 정보를 제공하기 때문에 내가 수집 한 것부터 시작합니다. 그러나 mod_plsql 페이지에서 호출 된 프로 시저 내에서 함수를 사용하면 오류 ORA-01857: not a valid time zone
이 발생합니다. tz
이 'UNK'
으로 설정되어 있기 때문에이 오류는 new_time
함수에서 발생합니다.
그래서, 난과 같이이 문제에 대한 해결 방법 구현 :
제외function unix_time_from_date(in_date in date) return number
as
ut number := 0;
tz varchar2(8) := '';
begin
-- Get the local timezone from the passed in date
-- Assuming the date supplied is for the local time zone
select
extract(
timezone_abbr from cast(in_date as timestamp with local time zone)
)
into tz
from dual;
if tz = 'UNK' then
select
extract(
timezone_abbr from cast(sysdate as timestamp with local time zone)
)
into tz
from dual;
end if;
-- Get the Unix timestamp
select
(new_time(in_date, tz, 'GMT') - to_date('01-JAN-1970', 'DD-MM-YYYY')) * (
86400)
into ut
from dual;
return ut;
end unix_time_from_date;
이 여전히 tz
이 'UNK'
로 설정하고 실패합니다. 아무도 여기서 무슨 일이 일어날 지 알고 있습니까? Oracle Application Server 프로세스에서 함수를 호출 할 때 현지 시간대 약어를 얻을 수없는 이유는 무엇입니까?
OAS 서버에서 sqlplus를 통해 이러한 쿼리를 실행하면 웹 페이지를 제공하는 사용자는 오류가 발생하지 않습니다. –