Solved

Converting SYSDATE to GMT

Posted on 2003-11-01
6
10,335 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
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 how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

772 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