oracle oracle中CURRENT_TIMESTAMP和SYSDATE不同
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17922106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Different CURRENT_TIMESTAMP and SYSDATE in oracle
提问by Mohsen Kashi
After executing this SQL in oracle 10g:
在 oracle 10g 中执行此 SQL 后:
SELECT SYSDATE, CURRENT_TIMESTAMP FROM DUAL
I receive this strange output:
我收到这个奇怪的输出:
What is cause of the difference in time? The server time is equal of SYSDATE value
时间差的原因是什么?服务器时间等于 SYSDATE 值
回答by Alex Poole
CURRENT_DATE
and CURRENT_TIMESTAMP
return the current date and time in the session time zone.
CURRENT_DATE
并CURRENT_TIMESTAMP
返回会话时区中的当前日期和时间。
SYSDATE
and SYSTIMESTAMP
return the system date and time - that is, of the system on which the database resides.
SYSDATE
并SYSTIMESTAMP
返回系统日期和时间——即数据库所在系统的日期和时间。
If your client session isn't in the same timezone as the server the database is on (or says it isn't anyway, via your NLS settings), mixing the SYS*
and CURRENT_*
functions will return different values. They are all correct, they just represent different things. It looks like your server is (or thinks it is) in a +4:00 timezone, while your client session is in a +4:30 timezone.
如果您的客户端会话与数据库所在的服务器不在同一个时区(或者说它不是,通过您的 NLS 设置),混合SYS*
和CURRENT_*
函数将返回不同的值。他们都是对的,他们只是代表不同的东西。看起来您的服务器处于(或认为是)+4:00 时区,而您的客户端会话处于 +4:30 时区。
You might also see small differences in the time if the clocks aren't synchronised, which doesn't seem to be an issue here.
如果时钟不同步,您可能还会看到时间上的细微差异,这在这里似乎不是问题。
回答by RaMs_YearnsToLearn
SYSDATE
, SYSTIMESTAMP
returns the Database's date and timestamp, whereas current_date
, current_timestamp
returns the date and timestamp of the location from where you work.
SYSDATE
,SYSTIMESTAMP
返回数据库的日期和时间戳,而current_date
,current_timestamp
返回您工作地点的日期和时间戳。
For eg. working from India, I access a database located in Paris. at 4:00PM IST:
例如。我在印度工作,访问位于巴黎的数据库。IST 下午 4:00:
select sysdate,systimestamp from dual;
This returns me the date and Time of Paris:
select sysdate,systimestamp from dual;
这将返回巴黎的日期和时间:
RESULT
结果
12-MAY-14 12-MAY-14 12.30.03.283502000 PM +02:00
select current_date,current_timestamp from dual;
This returns me the date and Time of India:
select current_date,current_timestamp from dual;
这将返回印度的日期和时间:
RESULT
结果
12-MAY-14 12-MAY-14 04.00.03.283520000 PM ASIA/CALCUTTA
Please note the 3:30 time difference.
请注意 3:30 的时差。
回答by Harshit
SYSDATE returns the system date, of the system on which the database resides
SYSDATE 返回数据库所在系统的系统日期
CURRENT_TIMESTAMP returns the current date and time in the session time zone, in a value of datatype TIMESTAMP WITH TIME ZONE
CURRENT_TIMESTAMP 以数据类型 TIMESTAMP WITH TIME ZONE 的值返回会话时区中的当前日期和时间
execute this comman
执行这个命令
ALTER SESSION SET TIME_ZONE = '+3:0';
and it will provide you the same result.
它将为您提供相同的结果。
回答by reddy
SYSDATE
provides date and time of a server.CURRENT_DATE
provides date and time of client.(i.e., your system)CURRENT_TIMESTAMP
provides data and timestamp of a clinet.
SYSDATE
提供服务器的日期和时间。CURRENT_DATE
提供客户的日期和时间。(即,您的系统)CURRENT_TIMESTAMP
提供客户端的数据和时间戳。
回答by Amir Abe
Note: SYSDATE - returns only date, i.e., "yyyy-mm-dd" is not correct. SYSDATE returns the system date of the database server including hours, minutes, and seconds. For example:
注意:SYSDATE - 仅返回日期,即“yyyy-mm-dd”不正确。SYSDATE 返回数据库服务器的系统日期,包括小时、分钟和秒。例如:
SELECT SYSDATE FROM DUAL; will return output similar to the following: 12/15/2017 12:42:39 PM
从 DUAL 中选择 SYSDATE;将返回类似于以下内容的输出:12/15/2017 12:42:39 PM
回答by sohan kumawat
SYSDATE
,systimestamp
return datetime of server where database is installed.SYSDATE
- returns only date, i.e., "yyyy-mm-dd".systimestamp
returns date with time and zone, i.e., "yyyy-mm-dd hh:mm:ss:ms timezone"now()
returns datetime at the time statement execution, i.e., "yyyy-mm-dd hh:mm:ss"CURRENT_DATE
- "yyyy-mm-dd",CURRENT_TIME
- "hh:mm:ss",CURRENT_TIMESTAMP
- "yyyy-mm-dd hh:mm:ss timezone". These are related to a record insertion time.
SYSDATE
,systimestamp
返回安装数据库的服务器的日期时间。SYSDATE
- 仅返回日期,即“yyyy-mm-dd”。systimestamp
返回带有时间和区域的日期,即“yyyy-mm-dd hh:mm:ss:ms timezone”now()
返回时间语句执行时的日期时间,即“yyyy-mm-dd hh:mm:ss”CURRENT_DATE
- "yyyy-mm-dd",CURRENT_TIME
- "hh:mm:ss",CURRENT_TIMESTAMP
- "yyyy-mm-dd hh:mm:ss 时区"。这些与记录插入时间有关。