我想不使用paste()将值插入到查询中,如下所示:
symbol<-'ES'
prices <- dbGetQuery(con,"SELECT * from fut_prices WHERE symbol LIKE '%:x%'",
x=symbol)上面返回的是fut_prices表中的所有列名,但没有返回行。我做错了什么?
发布于 2018-01-30 05:07:45
试试这个:
library(RSQLite)
con <- dbConnect(SQLite(), ":memory:")
DF <- data.frame(symbol = c("X", "ES"), price = 1:2, stringsAsFactors = FALSE)
dbWriteTable(con, "DF", DF)
s <- "SELECT * from DF where symbol LIKE '%' || :x || '%'"
symbol <- "ES"
bind.data <- data.frame(x = symbol, stringsAsFactors = FALSE)
dbGetPreparedQuery(con, s, bind.data = bind.data)给予:
symbol price
1 ES 2https://stackoverflow.com/questions/48508701
复制相似问题