1

输入(头(数据,10))

structure(list(DATE = c("14-04-2013 00:02:30", "14-04-2013 00:03:00", 
"14-04-2013 00:03:30", "14-04-2013 00:04:00", "14-04-2013 00:04:30", 
"14-04-2013 00:05:00", "14-04-2013 00:05:30", "14-04-2013 00:06:00", 
"14-04-2013 00:06:30", "14-04-2013 00:07:00"), LPAR = c("server1", 
"server1", "server1", "server1", "server1", 
"server1", "server1", "server1", "server1", 
"server1"), ENT = c("0.50", "0.50", "0.50", "0.50", "0.50", 
"0.50", "0.50", "0.50", "0.50", "0.50"), USR_SYS_CPU_PCT = c(73L, 
74L, 75L, 75L, 72L, 73L, 74L, 75L, 75L, 74L), ENT_PCT = c(345.6, 
397.7, 394.2, 418.6, 349.2, 358.9, 585.7, 443.8, 464.9, 483.1
), PHYSICAL_CPU_USED = c(1.73, 1.99, 1.97, 2.09, 1.75, 1.79, 
2.93, 2.22, 2.32, 2.42)), .Names = c("DATE", "LPAR", "ENT", "USR_SYS_CPU_PCT", 
"ENT_PCT", "PHYSICAL_CPU_USED"), row.names = c(NA, 10L), class = "data.frame")    

我正在尝试将 dat 数据框插入到名为 VMSTAT 的现有 oracle 表中。我正在做这个插入:

library(RODBC)
ch=odbcConnect("<dsn name>",pwd = "<password>")
sqlSave(ch,dat, tablename="VMSTAT",append=T)
odbcClose(ch)

不工作。我的 R 会话崩溃了。VMSTAT 表具有与数据框相同的列名。有没有人尝试将数据帧插入到 Oracle 表中,非常感谢任何帮助?

4

1 回答 1

1

我发现了问题所在。我在 oracle 表上的 DATE 字段是 DATE 但在数据框中是一个字符。我不得不使用:

dat$DATE<-as.POSIXct(dat$DATE, format="%d-%m-%Y %H:%M:%S")

它奏效了。

于 2013-04-15T18:03:47.210 回答