यहां उपरोक्त का मेरा संस्करण है। इसका लाभ यह है कि इसे दूसरे 'वैकल्पिक सत्र सेट समय क्षेत्र' की आवश्यकता नहीं है, और इसे एप्लिकेशन से अधिक आसानी से उपयोग किया जा सकता है। आप संग्रहीत फ़ंक्शन बनाते हैं, और फिर आप बस उपयोग करते हैं: वैकल्पिक सत्र SET time_zone = 'एशिया/जेरूसलम'; GetDSTDates (2012,1) DSTStart, GetDSTDates (2012,2) DSTEnd, सत्र TimeZone TZ दोहरी से चुनें;
जो निर्दिष्ट वर्ष के लिए डीएसटी प्रारंभ तिथि, डीएसटी समाप्ति तिथि, टाइमज़ोन वापस कर देगा।
create or replace function GetDSTDates
(
year integer,
GetFrom integer
)
return Date
as
cursor c is
select 12-to_number(to_char(LocalTimeZone at time zone '+00:00','HH24')) offset,
min(to_char(LocalTimeZone at time zone '+00:00','DD/MM/YYYY')) fromdate,
max(to_char(LocalTimeZone at time zone '+00:00','DD/MM/YYYY')) todate
from (
SELECT cast((to_date('01/01/'||to_char(year)||'12:00:00','MM/DD/YYYYHH24:MI:SS')+rownum-1) as timestamp with local time zone) LocalTimeZone
FROM dual CONNECT BY rownum<=365
)
group by 12-to_number(to_char(LocalTimeZone at time zone '+00:00','HH24'));
dstoffset integer;
offset integer;
dstfrom date;
dstto date;
begin
offset := 999;
dstoffset := -999;
for rec in c
loop
if rec.offset<offset
then
offset := rec.offset;
end if;
if rec.offset>dstoffset
then
dstoffset := rec.offset;
dstfrom := to_date(rec.fromdate,'DD/MM/YYYY');
dstto :=to_date(rec.todate,'DD/MM/YYYY');
end if;
end loop;
if (offset<999 and dstoffset>-999 and offset<>dstoffset)
then
if GetFrom=1
then
return dstfrom;
else
return dstto;
end if;
else
return null;
end if;
end;
/
ALTER SESSION SET time_zone='Asia/Jerusalem';
select GetDSTDates(2012,1) DSTStart,
GetDSTDates(2012,2) DSTEnd,
SessionTimeZone TZ from dual;
स्रोत
2012-05-24 19:18:34