【问题标题】:ROracle dbWriteTable affirms insertion that didnt happenROracle dbWriteTable 确认没有发生的插入
【发布时间】:2017-03-31 09:28:19
【问题描述】:

我的目标是在数据库中创建一个表,然后用数据填充它。这是我的代码:

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)

我已经成功了几次。该表已创建并填充。

现在第 4 步不再起作用,但 R 在执行 dbWriteTable 后返回 TRUE。但是桌子还是空的。

我知道这是一个模糊的问题,但有人知道这里可能出了什么问题吗?

【问题讨论】:

  • 我不认为这是一个模糊的问题。

标签: r roracle


【解决方案1】:

我找到了解决问题的方法。在步骤 3 中创建表后,您必须提交!然后将数据写入表中。

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)

【讨论】:

    猜你喜欢
    • 2015-05-09
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 2013-02-21
    • 2021-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多