简体   繁体   English

Oracle Timestamp UTC时间格式

[英]Oracle Timestamp UTC time format

CREATE TABLE DIALOGUE_TABLE(EXPIRE_TIME TIMESTAMP);

Following code snippet is inside stored proc : 以下代码段位于存储的proc内部:

PO_EXPIRETIME  :- OUT PARAM of procedure a varchar2

SELECT TO_CHAR(SYS_EXTRACT_UTC(EXPIRE_TIME)) 
  INTO PO_EXPIRETIME 
  FROM DIALOGUE_TABLE; 

When I run Stored Proc from server using EXEC and print PO_EXPIRETIME timestamp is proper with UTC format. 当我使用EXEC从服务器运行Stored Proc并打印PO_EXPIRETIME时间戳时,使用UTC格式是正确的。

But when I call stored procedure from OCCI and client the timestamp recieved is not same but that is the actual timestamp in table not UTC formatted. 但是,当我从OCCI和客户端调用存储过程时,接收到的时间戳并不相同,但这是表中未采用UTC格式的实际时间戳。

Maybe something I am missing but what I don't know? 也许我缺少了什么,但我不知道什么? Is there something in client side I need to do? 客户端需要做些什么吗?

If the column is declared as a TIMESTAMP and not, say, a TIMESTAMP WITH TIME ZONE or TIMESTAMP WITH LOCAL TIME ZONE, the timestamp that is stored in the table will not have a time zone component. 如果将该列声明为TIMESTAMP,而不是声明为TIMESTAMP WITH TIME ZONE或TIMESTAMP WITH LOCAL TIME ZONE,则表中存储的时间戳将没有时区成分。 As a result, SYS_EXTRACT_UTC will convert the timestamp to UTC using the session time zone which is something that is controlled by the client and may be different on different client machines. 结果,SYS_EXTRACT_UTC将使用会话时区将时间戳转换为UTC,该时区由客户端控制,并且在不同的客户端计算机上可能有所不同。 I suspect that if you run 我怀疑如果你跑步

SELECT SessionTimeZone
  FROM dual;

from your OCCI application and from your SQL*Plus session that you will end up with different results which is causing the strings returned to be different. 从OCCI应用程序和SQL * Plus会话中,您最终将获得不同的结果,这将导致返回的字符串不同。

If you want the string that is returned to be independent of the client machine, I would tend to suggest storing the time zone in the database column. 如果您希望返回的字符串与客户端计算机无关,则建议将时区存储在数据库列中。 Is changing the schema definition to use a TIMESTAMP WITH TIME ZONE an option? 是否可以将模式定义更改为使用带时区的TIMESTAMP? Barring that, you could ensure that every client machine has the same time zone configured and/or run an explicit ALTER SESSION, ie 除非这样做,否则您可以确保每个客户端计算机都配置了相同的时区和/或运行显式的ALTER SESSION,即

ALTER SESSION 
  SET time_zone = '-05:00';

in the stored procedure to ensure that the conversion is always done from a particular time zone. 在存储过程中,以确保始终在特定时区完成转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM