问题
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