我有一个函数可以捕获由odbcQuery
引起的错误。如何做到这一点,以便尝试删除不存在的表不会引发错误?
功能:
runQuery <- function(script, channel, errors = T) {
run <- odbcQuery(channel, script)
# if the function has returned an error
if (run == -1L) {
if (errors) {
err <- odbcGetErrMsg(channel)
cat("\nobdcQuery() encountered an error running the following SQL ")
cat("query:\n\n", script, "\n\nError from Oracle server:\n")
return(err)
} else {
err <- invisible(run)
}
}
}