[英]Oracle database timestamp to timestamp with timezone
Need help in inserting the data from timestamp , to timestamp with zone. 在从timestamp到带区域的timestamp插入数据时需要帮助。
create table foo ( tswtz TIMESTAMP WITH TIME ZONE);
SQL:>insert into foo values(systimestamp)
TSWTZ
---------------------------------------
09-08-16 11:39:21.199780000 AM +05:30
create table foo1 (test_dt timestamp)
insert into foo1 values(systimestamp)
TEST_DT
--------------------------------
09-08-16 11:40:55.242754000 AM
Now , there is a scenario, where i need to insert the values of foo1
to foo
. 现在,有一种情况,我需要将
foo1
的值插入foo
。 I have used the below command, 我使用了以下命令,
insert into foo (TSWTZ) (select CAST(TEST_DT AS TIMESTAMP WITH TIME ZONE) from foo1)
The select value displayed it as 选择值显示为
09-08-16 11:40:55.242754000 AM ASIA/CALCUTTA
But it should display it as 但是它应该显示为
09-08-16 11:40:55.242754000 AM +05:30.
Can you please help me on how to do that, without alter command ? 您能在没有alter命令的情况下帮助我该怎么做吗?
You need to alter your NLS parameters to get the result. 您需要更改NLS参数才能获得结果。 Please read the oracle documentation as well [ https://docs.oracle.com/cd/B19306_01/server.102/b14225/ch4datetime.htm][1]
请同时阅读oracle文档[ https://docs.oracle.com/cd/B19306_01/server.102/b14225/ch4datetime.htm][1]
Try setting: 尝试设置:
NLS_TIMESTAMP_TZ_FORMAT = DD-MON-RR HH.MI.SSXFF AM TZR
and NLS_TIMESTAMP_FORMAT = DD-MON-RR HH.MI.SSXFF AM
and NLS_TIME_TZ_FORMAT = HH.MI.SSXFF AM TZR
and NLS_TIME_FORMAT = HH.MI.SSXFF AM
Function SYSTIMESTAMP
returns current time in time zone of your database server operating system, in your case +05:30
. 函数
SYSTIMESTAMP
返回数据库服务器操作系统所在时区的当前时间,在您的情况下为+05:30
。
When you cast from TIMESTAMP
(without any time zone information) to TIMESTAMP WITH TIME ZONE
then Oracle takes your SESSIONTIMEZONE
- unless you specify the time zone explicitly. 当您从
TIMESTAMP
(无任何时区信息)转换为TIMESTAMP WITH TIME ZONE
Oracle会使用SESSIONTIMEZONE
除非您明确指定时区。
Obviously in your case the SESSIONTIMEZONE
is set to Asia/Calcutta
. 显然,您的情况是
SESSIONTIMEZONE
设置为Asia/Calcutta
。
In order to get desired result you can do either 为了获得理想的结果,您可以选择
ALTER SESSION SET TIME_ZONE = '+05:30';
or 要么
SELECT CAST((TEST_DT AT TIME ZONE '+05:30') AS TIMESTAMP WITH TIME ZONE)
FROM ...
Note, time zone Asia/Calcutta
is different than +05:30
, although the offset is the same. 请注意,时区
Asia/Calcutta
与+05:30
不同,尽管偏移量相同。 Region names like Asia/Calcutta
considers daylight saving times (which does not apply for Asia/Calcutta), UTC offsets like +05:30
do not consider daylight saving times. 区域名称(例如
Asia/Calcutta
考虑了夏令时(不适用于Asia / Calcutta),UTC偏移量(例如+05:30
不考虑夏令时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.