我有一个名为time的字符串变量,它保存时间值,如:
time = "2015.03.04";
我想将此变量传递给mysql以检索信息
rs <- dbSendQuery(mydb, "SELECT * FROM TIMETABLE WHERE Time LIKE",time," 13:30%");
现在打印出以下错误:
Error in mysqlExecStatement(conn, statement, ...) :
unused arguments ("2015.03.04", " 13:30%")
现在这是我到目前为止所得到的
sqlStatement <- paste("SELECT * FROM TIMETABLE WHERE Time LIKE '",time," 13:30%'")
sqlStatement
结果是:
> sqlStatement
[1] "SELECT * FROM TIMETABLE WHERE Time LIKE ' 2015.03.04 13:30%'"
我无法摆脱'
和2015
答案 0 :(得分:1)
猜我想自己回答这个问题,感谢所有的帮助!
我的解决方案似乎有点愚蠢,但解决了问题:)
time ="'2015.03.05";
sqlStatement <- paste("SELECT * FROM TIMETABLE WHERE Time LIKE ",time,"13:30%'")
答案 1 :(得分:0)
您的问题是由paste()引起的。您只需将“sep”参数设置为空字符串,因为默认值为空格。要使用您的示例:
sqlStatement <- paste("SELECT * FROM TIMETABLE WHERE Time LIKE '",time," 13:30%'", sep="")
快乐的查询!