问题描述
我不知道如何在R中更新现有的DB2数据库或在其中更新单个值.
I can't figure out how to update an existing DB2 database in R or update a single value in it.
除了非常笼统的信息外,我在网上找不到关于此主题的很多信息,但没有具体示例.
I can't find much information on this topic online other than very general information, but no specific examples.
library(RJDBC)
teachersalaries=data.frame(name=c("bob"), earnings=c(100))
dbSendUpdate(conn, "UPDATE test1 salary",teachersalaries[1,2])
AND
AND
teachersalaries=data.frame(name=c("bob",'sally'), earnings=c(100,200))
dbSendUpdate(conn, "INSERT INTO test1 salary", teachersalaries[which(teachersalaries$earnings>200,] )
推荐答案
您是否尝试过像使用其他语言一样传递常规SQL语句?
Have you tried passing a regular SQL statement like you would in other languages?
dbSendUpdate(conn, "UPDATE test1 set salary=? where id=?", teachersalary, teacherid)
或
dbSendUpdate(conn,"INSERT INTO test1 VALUES (?,?)",teacherid,teachersalary)
基本上,您可以使用参数标记(那些问号)指定常规SQL DML语句,并提供值列表作为逗号分隔的参数.
Basically you specify the regular SQL DML statement using parameter markers (those question marks) and provide a list of values as comma-separated parameters.
这篇关于使用R编写和更新DB2表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!