user1471980
user1471980

Reputation: 10646

unable to insert data frame to an existing oracle table

dput(head(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")    

I am trying to insert dat data frame to an existing oracle table called VMSTAT. I am doing to this insert:

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

not working. My R session is crashing. The VMSTAT table has the same column names as the data frame. Has anybody try to insert data frames to Oracle table, any help is really appreciated?

Upvotes: 1

Views: 988

Answers (1)

user1471980
user1471980

Reputation: 10646

I found out what the problem was. My DATE field on oracle table is as DATE but on the data frame was a character. I had to use:

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

and it worked.

Upvotes: 1

Related Questions