How can I get Time Zone Region from SQLPLUS?

十年热恋 提交于 2019-12-11 13:53:22

问题


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'"


回答1:


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;




回答2:


You could write a function in your application or in this trigger like this:

IF SESSIONTIMEZONE = '-4:00' THEN
   execute immediate 'ALTER SESSION SET time_zone = ''America/New_York''';
ELSIF SESSIONTIMEZONE = '-5:00' THEN
   execute immediate ...
END IF;


来源:https://stackoverflow.com/questions/23120840/how-can-i-get-time-zone-region-from-sqlplus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!