sta*_*ant 7 oracle timezone r posixct
我在R中使用ROracle访问Oracle数据库。
我注意到,大概是从夏季更改以来,任何DATE(日期时间)Oracle列现在都被错误地转换了(R中的小时数比Oracle DB中的小时数少)。
从小插图的第12页(我几乎不了解),它看起来像ROracle和R交换日期时间为自UTC 1970年1月1日以来的秒数,并且R随后针对本地时区进行了调整。
这是我的工作
drv <- dbDriver("Oracle");
con <- dbConnect(drv, username = Login, password = Pwd, dbname = DB, prefetch=TRUE, bulk_read=1e6);
test.query <- "SELECT * FROM MYTABLE WHERE ( A > to_date('2008-03-03 12:30:00', 'YYYY-MM-DD HH24:MI:SS') AND A < to_date('2008-03-03 12:40:00','YYYY-MM-DD HH24:MI:SS') AND [other stuff])"
test <- dbGetQuery(con, test.query);
head(test[,c("A","B","C")])
# A B C
#1 2008-03-03 11:30:38 2008-03-02 23:00:00 2008-03-02 23:00:00 #HERE IT SHOULD BE +1 HOUR
#2 2008-03-03 11:30:38 2008-03-02 23:00:00 2008-03-02 23:00:00
#3 2008-03-03 11:30:41 2008-03-02 23:00:00 2008-03-02 23:00:00
#4 2008-03-03 11:31:25 2008-03-02 23:00:00 2008-03-02 23:00:00
#5 2008-03-03 11:31:25 2008-03-02 23:00:00 2008-03-02 23:00:00
#6 2008-03-03 11:31:34 2008-03-02 23:00:00 2008-03-02 23:00:00
class(test$A)
[1] "POSIXct" "POSIXt"
attributes(test$A)
$class
[1] "POSIXct" "POSIXt"
Run Code Online (Sandbox Code Playgroud)
这是我的 sessionInfo()
sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.8.9 ROracle_1.1-7 DBI_0.2-5
loaded via a namespace (and not attached):
[1] tools_2.15.2
Run Code Online (Sandbox Code Playgroud)
这是有关我从管理员那里获得的Oracle DB的信息

我该怎么做才能正确解决此问题(不只是增加1小时,我必须在暑假结束时再取回)
小智 11
As you mentioned this is a timezone conversion which R is doing as per local timezone. For more details you can refer this link
http://www.oralytics.com/2015/05/r-roracle-and-oracle-date-formats_27.html
Try setting these system variables before connecting through ROracle
Sys.setenv(TZ = "GMT")
Sys.setenv(ORA_SDTZ = "GMT")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1900 次 |
| 最近记录: |