如何将 R 连接到 Oracle?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11037195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:53:58  来源:igfitidea点击:

How to Connect R to Oracle?

databaseoracler

提问by Mike_nmdp

I need to connect R to oracle and I have been unsuccessful so far. I downloaded two packages: RODBC & RODM.

我需要将 R 连接到 oracle,到目前为止我一直没有成功。我下载了两个包:RODBC 和 RODM。

This is the statement that I've been using:

这是我一直在使用的语句:

DB <- odbcDriverConnect("DBIORES1",uid="mhala",pwd="XXXXXXX")

But I get this error:

但我收到此错误:

Error in odbcDriverConnect("DBIORES1", uid = "mhalagan", pwd = "XXXXXXX") : 
  unused argument(s) (uid = "mhalagan", pwd = "XXXXXXX")

What information do I need to be able to connect to an oracle database? Am I using the correct package?

我需要什么信息才能连接到 oracle 数据库?我使用的是正确的包吗?

回答by jthetzel

See the help page for odbcDriverConnect(). odbcDriverConnect()does not accept uidor pwdarguments. You probably meant to use odbcConnect()instead:

参见帮助页面odbcDriverConnect()odbcDriverConnect()不接受uidpwd争论。您可能打算odbcConnect()改用:

odbcConnect(dsn = "DBIORES1", uid = "mhala", pwd = "XXXXXXX")

In addition to the RODBCpackage, there is the RODMpackage, which I believe is specifically designed for Oracle databases and is further described here: http://www.oracle.com/technetwork/articles/datawarehouse/saternos-r-161569.html. I do not use Oracle databases, so cannot comment on advantages of the two packages.

除了RODBC包之外,还有RODM包,我相信它是专门为 Oracle 数据库设计的,这里有进一步的描述:http: //www.oracle.com/technetwork/articles/datawarehouse/saternos-r-161569.html。我不使用 Oracle 数据库,因此无法评论这两个包的优点。

回答by jadianes

RJDBC worked just fine for me. You just need to have Oracle-thin driver jar file and configure the connection like:

RJDBC 对我来说工作得很好。您只需要拥有 Oracle-thin 驱动程序 jar 文件并像这样配置连接:

> install.packages("RJDBC")
> library(RJDBC)
> drv <- JDBC("oracle.jdbc.driver.OracleDriver","/path/to/driver/com/oracle/oracle-thin/11.2.0.1.0/oracle-thin-11.2.0.1.0.jar”)
> conn <- dbConnect(drv, "jdbc:oracle:thin:@database:port:schema”, “user”, “passwd”)

and then is ready to perform some queries.

然后准备好执行一些查询。

JA.

JA。

回答by MichaelN

Did you install the oracle ODBC client/driver? You will need that if you are going to use the ODBC R package. Go to oracle instant client downloadget the client for your OS. install them and then proceed to configure the ODBC and test the connection outside of R then install the R and RODBC and test inside R.

您是否安装了 oracle ODBC 客户端/驱动程序?如果您要使用 ODBC R 包,您将需要它。转至oracle 即时客户端下载,获取适用于您操作系统的客户端。安装它们,然后继续配置 ODBC 并测试 R 外部的连接,然后安装 R 和 RODBC 并在 R 内部进行测试。

回答by Sean

I've had success in the past connecting to Oracle databases from R with RJDBC. I found it easier to get going as I just grabbed the connection string that I'd used successfully inside the java based GUI I was using at the time and like magic it "just works"(tm).

我过去曾成功地使用 RJDBC 从 R 连接到 Oracle 数据库。我发现它更容易开始,因为我只是抓住了我在当时使用的基于 Java 的 GUI 中成功使用的连接字符串,就像魔术一样它“正常工作”(tm)。