在 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 adata.frame
(which should agree with the bound specification) in calls todbExecStatement
to be executed for each row of thedata.frame
.
我做错了吗,或者上面的措辞可能只适用于INSERT
/UPDATE
语句?
最佳答案
我觉得你误会了。
本质上,您的 SQL 有一个绑定(bind)变量,但您正试图绑定(bind)两个值。第二个值被丢弃。也许您可以在 SQL 中使用 IN
运算符来做类似的事情。
关于oracle - ROracle SELECT 语句中的绑定(bind)参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3622375/