无法将数据框插入现有的oracle表

时间:2013-04-15 14:46:36

标签: r oracle

dput(头(DAT,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表,真的很感激任何帮助吗?

1 个答案:

答案 0 :(得分:1)

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

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

并且有效。