Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Converting SYSDATE to GMT

Posted on 2003-11-01
6
Medium Priority
?
10,472 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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 1000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

722 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