Solved

Converting SYSDATE to GMT

Posted on 2003-11-01
6
10,295 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Oracle queries --Challenging Question 12 62
query returning everything 11 66
dates - loop 12 40
Maintaining Oracle Managed Accounts 2 15
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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 shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now