我正在尝试将 R/Shiny/SQL 应用程序转换为使用来自 SQL Server 而不是 Oracle 的数据。原代码中有很多如下类型条件:如果表存在,则将其作为数据集,否则上传新数据。我一直在寻找 DBI/ROracle
包中的 dbExistsTable
命令的对应项,但不幸的是 odbcTableExists
只是内部 RODBC
命令在 R
环境中不可用。也是 RODBC
包的包装器,允许使用 DBI
类型的命令 - RODBCDBI
似乎不起作用。有任何想法吗?
这是一些代码示例:
library(RODBC)
library(RODBCDBI)
con <- odbcDriverConnect('driver={SQL
Server};server=xx.xx.xx.xxx;database=test;uid=user;pwd=pass123')
odbcTableExists(con, "table")
错误:找不到函数“odbcTableExists”
dbExistsTable(con,"table")
错误(函数(类,fdef,mtable): 无法为签名““RODBC”、“字符””找到函数“dbExistsTable”的继承方法
最佳答案
你可以使用
[Table] %in% sqlTables(conn)$TABLE_NAME
其中[Table]
是您要查找的表的字符串。
关于sql - RODBC 包 : How to get a logical value for the "Does the Table Exists?" query type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34755382/