Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting SYSDATE to GMT

Posted on 2003-11-01
6
Medium Priority
?
10,494 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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
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

Technology Partners: 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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
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 explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

782 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