ROracle dbWriteTable 确认没有发生的插入
ROracle dbWriteTable affirms insertion that didnt happen
我的目标是在数据库中创建一个 table,然后用数据填充它。这是我的代码:
library(ROracle)
# ... "con" is the connection string, created in an earlier stage!
# 1 create example
testdata <- data.frame(A = c(1,2,3), B = c(4,5,6))
# 2 create-statement
createTable <- paste0("CREATE TABLE TestTable(", paste(paste(colnames(testdata), c("integer", "integer")), collapse = ","), ")")
# 3 send and execute query
dbGetQuery(con, createTable)
# 4 write example data
dbWriteTable(con, "TestTable", testdata, row.names = TRUE, append = TRUE)
我已经成功过几次了。 table 已创建并填充。
现在第 4 步不再起作用,R returns 执行 dbWriteTable
后为 TRUE。但是 table 仍然是空的。
我知道这是一个模糊的问题,但是有人知道这里可能出了什么问题吗?
我找到了解决问题的方法。在步骤 3 中创建 table 之后,您必须提交!之后,数据被写入table.
library(ROracle)
# ... "con" is the connection string, created in an earlier stage!
# 1 create example
testdata <- data.frame(A = c(1,2,3), B = c(4,5,6))
# 2 create-statement
createTable <- paste0("CREATE TABLE TestTable(", paste(paste(colnames(testdata), c("integer", "integer")), collapse = ","), ")")
# 3 send and execute query
dbGetQuery(con, createTable)
# NEW LINE: COMMIT!
dbCommit(con)
# 4 write example data
dbWriteTable(con, "TestTable", testdata, row.names = TRUE, append = TRUE)
我的目标是在数据库中创建一个 table,然后用数据填充它。这是我的代码:
library(ROracle)
# ... "con" is the connection string, created in an earlier stage!
# 1 create example
testdata <- data.frame(A = c(1,2,3), B = c(4,5,6))
# 2 create-statement
createTable <- paste0("CREATE TABLE TestTable(", paste(paste(colnames(testdata), c("integer", "integer")), collapse = ","), ")")
# 3 send and execute query
dbGetQuery(con, createTable)
# 4 write example data
dbWriteTable(con, "TestTable", testdata, row.names = TRUE, append = TRUE)
我已经成功过几次了。 table 已创建并填充。
现在第 4 步不再起作用,R returns 执行 dbWriteTable
后为 TRUE。但是 table 仍然是空的。
我知道这是一个模糊的问题,但是有人知道这里可能出了什么问题吗?
我找到了解决问题的方法。在步骤 3 中创建 table 之后,您必须提交!之后,数据被写入table.
library(ROracle)
# ... "con" is the connection string, created in an earlier stage!
# 1 create example
testdata <- data.frame(A = c(1,2,3), B = c(4,5,6))
# 2 create-statement
createTable <- paste0("CREATE TABLE TestTable(", paste(paste(colnames(testdata), c("integer", "integer")), collapse = ","), ")")
# 3 send and execute query
dbGetQuery(con, createTable)
# NEW LINE: COMMIT!
dbCommit(con)
# 4 write example data
dbWriteTable(con, "TestTable", testdata, row.names = TRUE, append = TRUE)