Solved

Converting SYSDATE to GMT

Posted on 2003-11-01
6
10,373 Views
Last Modified: 2007-12-19
Hi All,

My requirement is to convert the sysdate to GMT time. I am using oracle 8i. I cannot use the new_time function as the timezone in which my databases are +8:00 and +5:30 hrs.

I tried  the DBTIMEZONE  function to get the GMT time difference could and successfully convert the sysdate to GMT in SQL*Plus. But this does not work in the PL/SQL block where I need this value. It says DBTIMEZONE needs to be decalred.

Can anyone please help me with this.

Thanks in advance..
Regards,
Vikas D
0
Comment
Question by:Vikas_Dixit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:seazodiac
ID: 9663169
DBTIMEZONE is disabled in PL/SQL block.
if you dare to do, hack the STANDARD.SQL file in <oracle_home>/rdbms/admin folder.

comment these lines out (will not affect database, at least it does not do any harm to my database).
  -- pragma new_names('8.1.5',
  --                  time,"TIME WITH TIME ZONE",
  --                  timestamp,"TIMESTAMP WITH TIME ZONE",
  --                  "INTERVAL DAY TO SECOND",
  --                  "INTERVAL YEAR TO MONTH",
  --                  to_time, to_timestamp,
  --                  to_time_tz, to_timestamp_tz,
  --                  " SYS$DSINTERVALSUBTRACT",
  --                  " SYS$YMINTERVALSUBTRACT",
  --                  to_yminterval,to_dsinterval,
  --                  NUMTOYMINTERVAL, NUMTODSINTERVAL,
  --                  current_date,
  --                  current_time,current_timestamp);

  -- pragma new_names('8.1.6',
  --                  dbtimezone, sessiontimezone, localtimestamp,
  --                  localtime, to_local_tz, to_db_tz,
  --                  cube, rollup, grouping);


And then  in the SQLPLUS window, recompile it:

SQL>@STANDARD.sql

then you need to bounce the database (restart the database) to make that change  take effect.
it works like a charm for me:

----Before I did the above steps:

declare
l_tztest VARCHAR2(50);
l_datetest DATE;
begin
select dbtimezone into l_tztest from dual;
select sysdate into l_datetest from dual;
dbms_output.put_line(l_tztest);
dbms_output.put_line(l_datetest);
end;
/


The error message I got:

ERROR at line 5:
ORA-06550: line 5, column 8:
PLS-00201: identifier 'SESSIONTIMETONE' must be declared
ORA-06550: line 5, column 1:
PL/SQL: SQL Statement ignored



After recompiling it and restart the database, the same code:

-05:00
01-NOV-03


By the way, I am using Oracle 8.1.7 to test this, but it works in oracle 8.1.6 too.
Hope this helps
0
 
LVL 23

Expert Comment

by:seazodiac
ID: 9663177
ERROR at line 5:
ORA-06550: line 5, column 8:
PLS-00201: identifier 'SESSIONTIMETONE' must be declared  ---It should be 'DBTIMEZONE', but I also tested                
                                                                                                ----SESSIONTIMEZONE.
ORA-06550: line 5, column 1:
PL/SQL: SQL Statement ignored
0
 
LVL 8

Author Comment

by:Vikas_Dixit
ID: 9663554
Hi seazodiac,

Thanks for the prompt reply..

I stumbled upon this method earlier, i fear i can't easily use this method, as the environment is a tightly controlled one..

Isn't there a simpler method for the same... The requirement sounded quiet simple to me earleir and I thought many would have face similar kind of issue, and there will be some straight forward solution...

Regards,
Vikas D
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:seazodiac
ID: 9664482
How do this one sound to you?
"alter database set time_zone  = <value>"

Or how about just  pass a time_zone format string to the procedure like '-08:00' since dbtimezone or sessiontimezone returns VARCHAR2 type too.
0
 
LVL 5

Accepted Solution

by:
gmyers earned 250 total points
ID: 9668772
Dynamic SQL works fine

declare
l_tztest VARCHAR2(50);
l_datetest DATE;
begin
execute immediate 'select dbtimezone from dual'  into l_tztest ;
select sysdate into l_datetest from dual;
dbms_output.put_line(l_tztest);
dbms_output.put_line(l_datetest);
end;
0
 
LVL 8

Author Comment

by:Vikas_Dixit
ID: 9676235
Thanks gmyers

Works great!!!

Regards,
Vikas Dixit.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to take different types of Oracle backups using RMAN.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question