Oracle – How to get Time Zone Region from SQLPLUS

oracleoracle11gsqlplus

I am using Oracle Developer and Oracle 11g (Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – Production)

select SESSIONTIMEZONE from DUAL;

Result in SQLPLUS/system_config_tbl_load.sql: -4:00
Result in SQL Developer: America/New_York

gives different results in SQL Developer and SQLPLUS.
I want to see the region in SQLPLUS.

Additionally I have to do this for multiple locations and do not have the option of changing the Time Zone using "ALTER SESSION SET time_zone = 'America/New_York'"

Best Answer

I assume SQL Developer makes an implict ALTER SESSION SET time_zone=... when you open a new connection.

I see several solutions:

  • Define environment variable TZ on client host
  • Create a database trigger and set timezone accordingly
  • Change the timezone of the database - works unless any user sets his personal timezone

Database Trigger:

CREATE OR REPLACE TRIGGER LOG_T_LOGON 
   AFTER LOGON ON DATABASE
DECLARE

BEGIN
   IF ora_login_user IS NULL THEN 
      RETURN;
   END IF;
   IF ora_login_user IN (...) THEN -- Prevent to be executed for EACH user
      execute immediate 'ALTER SESSION SET time_zone = ''America/New_York''';
   END IF;
END;

END;

Related Topic