我寫了一個函數將日期轉換爲Unix時間戳。無論當前的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應用服務器進程調用該函數時,爲什麼我無法獲取本地時區縮寫?
通過OAS服務器上的sqlplus執行這些查詢,因爲提供網頁的用戶不會導致錯誤。 – 2012-02-10 13:59:42