Connect to ORACLE via R, using the info in sql developer

烈酒焚心 提交于 2019-12-24 19:54:14

问题


I am working on a machine without admin rights. I use sql developer to connect to an internal database. I would like to connect via R also.

Is there any way I can do this, without admin rights? Some solutions require me to set up a systemDNS - which I can not do. Other requires me to install jvm.dll

My environment: Windows7, sqldeveloper, connection method is via TNS file.


回答1:


Connecting to SQL Developer via R is far more difficult than other databases I've encountered. It's important that you have jdbc6.jar installed on your machine, and that you know the file path to where it was installed. Installing the jar file does not require admin rights. You can install the jar file from Oracle's website.

I use the RJDBC package to connect like so:

    library(RJDBC)

    jdbcDriver <- JDBC("oracle.jdbc.OracleDriver", classPath = "file path to where ojdbc6.jar is installed on your computer")

    jdbcConnection <- dbConnect(jdbcDriver, "jdbc:oracle:thin:@YOUR_SERVER","YOUR_USERNAME","YOUR_PASSWORD")

You can then test the connection with a number of commands; I typically use:

    dbListTables(jdbcConnection)

Another favorite of mine is to use dbplyr for dplyr-like functions when working with databases:

    library(dbplyr)

    tbl(jdbcConnection, "SAMPLE_TABLE_NAME")

The resulting output will be the data from the queried table in tibble form.




回答2:


You can set the environment variables in your R session.

Sys.setenv(OCI_LIB64="/Path/to/instantclient",OCI_INC="/Path/to/instantclient/sdk/include")

You can put this in the file .Rprofile in your home directory, and RStudio will run it each time you begin a new session. Once you have this in .Rprofile you should be able to install ROracle.



来源:https://stackoverflow.com/questions/51437217/connect-to-oracle-via-r-using-the-info-in-sql-developer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!