简体   繁体   English

如何将R连接到Oracle?

[英]How to Connect R to Oracle?

I need to connect R to oracle and I have been unsuccessful so far. 我需要将R连接到oracle,到目前为止,我一直没有成功。 I downloaded two packages: RODBC & RODM. 我下载了两个软件包: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? 我需要什么信息才能连接到oracle数据库? Am I using the correct package? 我使用的是正确的包裹吗?

See the help page for odbcDriverConnect() . 请参阅odbcDriverConnect()的帮助页面。 odbcDriverConnect() does not accept uid or pwd arguments. odbcDriverConnect()不接受uidpwd参数。 You probably meant to use odbcConnect() instead: 您可能打算改用odbcConnect()

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

In addition to the RODBC package, there is the RODM package, 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 . 除了RODBC软件包之外,还有RODM软件包,我相信它是专门为Oracle数据库设计的,并在此处进一步描述: 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. 我不使用Oracle数据库,因此无法评论这两个软件包的优点。

RJDBC worked just fine for me. RJDBC对我来说很好。 You just need to have Oracle-thin driver jar file and configure the connection like: 您只需要具有Oracle瘦驱动程序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。

Did you install the oracle ODBC client/driver? 您是否安装了oracle ODBC客户端/驱动程序? You will need that if you are going to use the ODBC R package. 如果您要使用ODBC R包,则将需要它。 Go to oracle instant client download get the client for your OS. 转到oracle Instant Client下载,获取适用于您的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. 安装它们,然后继续配置ODBC并测试R外部的连接,然后安装R和RODBC并在R内部进行测试。

I've had success in the past connecting to Oracle databases from R with RJDBC. 过去,我已经成功地通过RJDBC与R连接到Oracle数据库。 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). 我发现更容易上手,因为我只是抓住了我当时使用的基于Java的GUI中成功使用的连接字符串,并且喜欢魔术,它“可以正常工作”(tm)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM