如何使用包含 DB 的字符而不是 R 中的连接?

问题描述 投票:0回答:1

我有一个这样的数据库

library(RSQLite)
test <- dbConnect(RSQLite::SQLite(), "")
dbWriteTable(test, "mtcars", mtcars)

char_string <- "test"

如何使用

char_string
dbListTables
来查看数据库中的表?

r
1个回答
0
投票

列出所有表的通用原始 SQLite 查询是:

SELECT name FROM sqlite_master WHERE type = 'table';

您可以从 R 端执行此查询,使用:

library(RSQLite)
test <- dbConnect(RSQLite::SQLite(), "")
sql <- "SELECT name FROM sqlite_master WHERE type = 'table'"
tables <- dbGetQuery(test, sql)
tables
© www.soinside.com 2019 - 2024. All rights reserved.