0
我有,例如數據幀:插入來自R數據框中多行到Oracle數據庫
df <- as.data.frame(matrix(sample(c(NA, 1:50), 49, replace = TRUE), 7))
它看起來像這樣:
V1 V2 V3 V4 V5 V6 V7
1 46 6 23 7 22 42 1
2 47 33 47 50 42 NA 49
3 14 35 49 48 37 10 22
4 42 23 5 4 41 46 48
5 32 36 24 26 19 31 45
6 26 47 28 19 34 19 32
7 37 13 46 46 NA 22 49
現在我想寫這個數據幀到Oracle數據庫無使用sqlSave,因爲我有一個巨大的data.frame和R Studio崩潰,如果我這樣做。相反,我決定用sqlquery的做到這一點:
library(RODBC)
connHandle <- odbcConnect("DBName", uid="user", pwd="password")
sqlQuery(connHandle, sprintf("INSERT INTO MYTABLE VALUES %s", stringWithMyDataframeValues))
close(connHandle)
我已閱讀this後,但它並沒有爲我工作。
這樣做的最佳方式是什麼?我想要通過的字符串應該如何處理?提前致謝。