使用 r 编写和更新 DB2 表 [英] Writing and Updating DB2 tables with r

查看:22
本文介绍了使用 r 编写和更新 DB2 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在 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])

<小时>

       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=?", teacheralary, 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 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆