Oracle Timezone - Brazil 2018 change - oracle

Similar to the issue described in the post:
But for Oracle database itself.
There's a database running on machine whose timezone/clock is set to Brazil/East/Brasilia/SaoPaulo time. We use this query to get the database clock and convert it to GMT:
SELECT to_char(sysdate, 'YYYY-MM-DD HH24:MI') AS MY_SYSDATE
, TO_CHAR(FROM_TZ (CAST (SYSDATE AS TIMESTAMP), 'America/Sao_Paulo') AT TIME ZONE 'GMT'
, 'YYYY-MM-DD HH24:MI') as gmt_brazil_east
, TO_CHAR(FROM_TZ (CAST (SYSDATE AS TIMESTAMP), 'Etc/GMT+3') AT TIME ZONE 'GMT', 'YYYY-MM-DD HH24:MI') as gmt_03
FROM DUAL
WHERE 1=1
;
Every since this past weekend, the value for the field "gmt_brazil_east" is wrong... I suspect because our Oracle hasn't been updated to reflect the recent change regarding when Brazil changes daylight-savings... Described here:
Though our database version is recent, it is Oracle Database 12c Standard Edition Release 12.2.0.1.0 - 64bit Production
I tried finding info on this similar to the Java-related post above, but could not... Does anyone know where I can find which version/patch of Oracle has this change to Brazil timezone corrected?

Don't know if you have access to Oracle Support, but there is a patch to DSTv32 for Oracle 11.2.0.3.0 until 18.3 available.
Have a look here Brazil to Start DST on November From 2018 Onwards- Impact on Oracle RDBMS (Doc ID 2331560.1)

Related

Change Oracle ADW default timezone

The ADW is configured for UTC timezone and there is need to change it to EST timezone.
The ETL custom application has many stored custom procedures which SYSDATE returns the current date and time set for the operating system.
What is the best approach to solve this problem in ADW?
To change timezone please refer here.
Note that this does not change the output of SYSDATE as that relies on the OS timezone which cannot be changed. The recommendation is to use CURRENT_DATE instead.
Upgrade Example
This example illustrates updating DST behavior to Oracle Database 11g,
release 2 for which the default time zone version is 14. First, assume
that your current database is using time zone version 3, and also
assume you have an existing table t, which contains timestamp with
time zone data.
Connect to the database as the user scott and execute the following
statements:
DROP TABLE t;
CREATE TABLE t (c NUMBER, mark VARCHAR(25), ts TIMESTAMP WITH TIME ZONE);
INSERT INTO t VALUES(1, 'not_affected',
to_timestamp_tz('22-sep-2006 13:00:00 america/los_angeles',
'dd-mon-yyyy hh24:mi:ss tzr tzd'));
INSERT INTO t VALUES(4, 'affected_err_exist',
to_timestamp_tz('11-mar-2007 00:30:00 america/st_johns',
'dd-mon-yyyy hh24:mi:ss tzr tzd'));
INSERT INTO t VALUES(6, 'affected_no_err',
to_timestamp_tz('11-mar-2007 01:30:00 america/st_johns',
'dd-mon-yyyy hh24:mi:ss tzr tzd'));
INSERT INTO t VALUES(14, 'affected_err_dup',
to_timestamp_tz('21-sep-2006 23:30:00 egypt',
'dd-mon-yyyy hh24:mi:ss tzr tzd'));
COMMIT;
Then, optionally, you can start a prepare window to check the affected
data and potential semantic errors where there is an overlap or
non-existing time. To do this, you should start a window for
preparation to migrate to time zone version 14. It is assumed that you
have the necessary privileges. These privileges are controlled with
the DBMS_DST package.

Oracle server timezone using SQL query

I ran
select SYSDATE from dual;
Output:
SYSDATE |
-------------------|
2019-10-09 08:55:29|
Then I ran,
SELECT DBTIMEZONE FROM DUAL;
Output:
DBTIMEZONE|
----------|
+00:00 |
In the first output, time is in EST and 2nd output suggests timezone is UTC.
How do I check oracle server timezone via SQL query?
From the docs:
The database time zone [DBTIMEZONE] is relevant only for TIMESTAMP WITH LOCAL TIME ZONE columns. Oracle recommends that you set the database time zone to UTC (0:00)...
SYSDATE/SYSTIMESTAMP will return the time in the database server's OS timezone. Selecting a TIMESTAMP WITH LOCAL TIME ZONE datatype will return the time in your session's timezone (ie, SESSIONTIMEZONE).
select
CAST(systimestamp AS timestamp(0) with local time zone) as local_time,
systimestamp as server_time
from dual;
DBTIMEZONE is only used as the base timezone stored in TIMESTAMP WITH LOCAL TIME ZONE columns - which you never see, because when you select from one of those columns it gets translated into your session timezone.
See this similar question for a very detailed answer.
It is a common misunderstanding that SYSDATE or SYSTIMESTAMP are returned at DBTIMEZONE
SYSDATE and SYSTIMESTAMP are given in the time zone of database server's operating system. If you like to interrogate the time zone of database server's operating system run
SELECT TO_CHAR(SYSTIMESTAMP, 'tzr') FROM dual;
see also How to handle Day Light Saving in Oracle database

Timezone Region Not Found (Oracle 11g)

Does anyone know why the first query would be causing this error to be thrown while the second one works?
ORA-01882: timezone region not found 01882. 00000 - "timezone region %s not found"
Causes Error: SELECT SYSTIMESTAMP AT TIME ZONE (SELECT t.TIME_ZONE FROM SOME_TABLE t WHERE t.TIME_ZONE = 'America/Denver' AND ROWNUM = 1)
FROM DUAL
Works Correctly: SELECT SYSTIMESTAMP AT TIME ZONE (SELECT 'America/Denver' FROM SOME_TABLE t WHERE ROWNUM = 1)
FROM DUAL
Note: This is running on a Oracle Database 11g Release 11.2.0.4.0 - 64bit db. I've verified both queries work correctly on another db with the same db version. Not sure what else could be causing this.
To summarize the root cause, it was related to t.TIME_ZONE's data type (which was NVARCHAR2). Here's an example showing that NVARCHAR2 time zone names are not supported in 11g:
Does not work: SELECT SYSTIMESTAMP AT TIME ZONE CAST( 'America/Denver' as NVARCHAR2(80)) FROM DUAL
Works: SELECT SYSTIMESTAMP AT TIME ZONE CAST( 'America/Denver' as VARCHAR2(80)) FROM DUAL
Wrapping t.TIME_ZONE in TO_CHAR() fixed the problem.

Toad SQL Issue for Timestamp without Seconds

I am executing the following sql in Toad. Oracle is RDBMS
I only need Date in yyyymmdd HH24:mi, but I get Date only as shown below
alter session set nls_date_format = 'DD/MM/YYYY HH24:MI';
SELECT to_date('22/07/1980 00:00','dd/mm/yyyy hh24:mi') dt FROM dual
22/07/1980
Required Output
22/07/1980 00:00
You are looking for to_char() -- you want to return the date as a string, not a date. As far as I know, the date is returned without the time, and I don't think the NLS changes that.
So:
SELECT to_char(to_date('22/07/1980 00:00', 'dd/mm/yyyy hh24:mi'
), 'DD/MM/YYYY HH24:MI'
) as dt
FROM dual
I have used sql plus and spooled the file instead of Toad, used NLS Date format conversion here, but as this is command based, wanted to use GUI based TOAD.

How to get UTC value for SYSDATE on Oracle

Probably a classic... Would you know a easy trick to retrieve an UTC value of SYSDATE on Oracle (best would be getting something working on the 8th version as well).
For now I've custom function :(
Cheers,
Stefan
You can use
SELECT SYS_EXTRACT_UTC(TIMESTAMP '2000-03-28 11:30:00.00 -02:00') FROM DUAL;
You may also need to change your timezone
ALTER SESSION SET TIME_ZONE = 'Europe/Berlin';
Or read it
SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM dual;
select sys_extract_utc(systimestamp) from dual;
Won't work on Oracle 8, though.
Usually, I work with DATE columns, not the larger but more precise TIMESTAMP used by some answers.
The following will return the current UTC date as just that -- a DATE.
CAST(sys_extract_utc(SYSTIMESTAMP) AS DATE)
I often store dates like this, usually with the field name ending in _UTC to make it clear for the developer. This allows me to avoid the complexity of time zones until last-minute conversion by the user's client. Oracle can store time zone detail with some data types, but those types require more table space than DATE, and knowledge of the original time zone is not always required.
I'm using:
SELECT CAST(SYSTIMESTAMP AT TIME ZONE 'UTC' AS DATE) FROM DUAL;
It's working fine for me.
If you want a timestamp instead of just a date with sysdate, you can specify a timezone using systimestamp:
select systimestamp at time zone 'UTC' from dual
outputs: 29-AUG-17 06.51.14.781998000 PM UTC

Resources