How to Use R Language to Connect with an ORACLE Database

The language R can be used to connect with an ORACLE database and perform several actions. For use on Linux Ubuntu and ORACLE XE, learning to connect in this way makes the task much more manageable. Choose your OS (Linux 32) here:...

Method 1 of 5:

Instant Client + ODBC packages

  1. Picture 1 of How to Use R Language to Connect with an ORACLE Database
    Choose your OS (Linux 32) here:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
  2. Picture 2 of How to Use R Language to Connect with an ORACLE Database
    Accept the License Agreement and agree to download:
      1. Instant Client Package - Basic
      2. Instant Client Package - ODBC
  3. Picture 3 of How to Use R Language to Connect with an ORACLE Database
    Unzip both packages in the same directory. For example, /home/sven/instantclient_11_2
Method 2 of 5:

Unixodbc

  1. Picture 4 of How to Use R Language to Connect with an ORACLE Database
    Download unixodbc from here: http://www.unixodbc.org/download.html.
  2. Picture 5 of How to Use R Language to Connect with an ORACLE Database
    Install it.
Method 3 of 5:

Edit odbc.ini & odbcinst.ini

  1. Picture 6 of How to Use R Language to Connect with an ORACLE Database
    Find the two .ini files. These are located in /etc/ (Ubuntu). Perhaps there are similar files in other locations; if so, it's recommended that you delete them.
  2. Picture 7 of How to Use R Language to Connect with an ORACLE Database
    Add a new entry like this:
    1. For odbc.ini ...
  1. [ORACLE2]
  2. Driver = ORACLE2
  3. ServerName = 143.93.91.33:1521/xe
  4. UserID = your_username
  5. Password = xxx
  6. METADATA_ID = 0
  7. ENABLE_USER_CATALOG = 1
  8. ENABLE_SYNONYMS = 1
    1. For odbcinst.ini ...
  9. [ORACLE2]
  10. Description = oracle driver
  11. Driver = /home/sven/instantclient_11_2/libsqora.so.11.1
  12. DontDLClose = 1
  13. FileUsage = 1
  14. UsageCount = 1
    1. Notes: 'Driver' points at the file 'libsqora.so.11.1' in the Instant-client location.
Method 4 of 5:

Add to your path

  1. Picture 8 of How to Use R Language to Connect with an ORACLE Database
    You may need to add 2 entries to your path (example):
    export OCI_LIB=/home/sven/instantclient_11_2
    Picture 9 of How to Use R Language to Connect with an ORACLE Database
    export LD_LIBRARY_PATH=/home/sven/instantclient_11_2
Picture 10 of How to Use R Language to Connect with an ORACLE Database
Method 5 of 5:

The R language

  1. Picture 11 of How to Use R Language to Connect with an ORACLE Database
    Obtain a package called 'RODBC' in order to connect with the database. Download it here: http://cran.r-project.org/web/packages/RODBC/index.html
  2. Picture 12 of How to Use R Language to Connect with an ORACLE Database
    Start R, switch to the location which contains the RODBC package and an enter the following R code:
    1. install.packages(packagename.tar.gz)
  3. Picture 13 of How to Use R Language to Connect with an ORACLE Database
    After the package installation you can create a channel:
    1. ch=odbcConnect("ORACLE2")
  4. Check the channel with odbcGetInfo(ch)
  5. If the connection was successful, the console shows something like this:
  1. odbcGetInfo(ch)
  2. DBMS_Name DBMS_Ver Driver_ODBC_Ver
  3. "Oracle" "10.02.0010" "03.52"
  4. Data_Source_Name Driver_Name Driver_Ver
  5. "ORACLE2" "SQORA32.DLL" "11.02.0001"
  6. ODBC_Ver Server_Name
  7. "03.52" "143.93.91.33:1521/xe"
Update 05 March 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile