oracle - ROracle SELECT 语句中的绑定(bind)参数

标签 oracle r

R 中使用 ROracle 时,我想将一些参数绑定(bind)到数据,所以我这样做:

> dbh <- dbConnect('Oracle', 'user/pass@host.com:port/sid')
> st <- dbPrepareStatement(dbh, statement="SELECT x FROM mytab WHERE id=:1",
                           bind="character")
> st <- dbExecStatement(st, data.frame(id=c("9ae", "1f3"), stringsAsFactors=F))
> fetch(st)
    x
0 FOO

出乎意料的是它只使用数据框的 first 行来执行 SELECT(如果它同时使用这两行,我会得到 2 个输出行在这种情况下,不是 1),与 ROracle 文档相反:

The object that dbPrepareStatement produces is then used together with a data.frame (which should agree with the bound specification) in calls to dbExecStatement to be executed for each row of the data.frame.

我做错了吗,或者上面的措辞可能只适用于INSERT/UPDATE 语句?

最佳答案

我觉得你误会了。

本质上,您的 SQL 有一个绑定(bind)变量,但您正试图绑定(bind)两个值。第二个值被丢弃。也许您可以在 SQL 中使用 IN 运算符来做类似的事情。

关于oracle - ROracle SELECT 语句中的绑定(bind)参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3622375/

相关文章:

java - 将 Eclipse(Java) 连接到 Oracle 数据库

list - 在 R 列表中插入元素

循环 : file(con, "r") 和 open.connection(con, "rb") 中的 R 错误

r - 匹配时间范围之前和之后的记录

r - 如何将列表添加到 R 中的数据框?

r - 通过两个列表的复杂比较创建一个列表

Oracle Apex/PLSQL : Can i use apex data export to store the file into another table as a blob?

Oracle APEX Interactive Report 条件列链接显示

sql - sql中的trunc和round函数

sql - 不兼容的类型 : numeric and bigint. 在 PostgreSQL 中