- install unixodbc using homebrew
You can install homebrew here. Once that is done, run this in the terminal.
brew install unixodbc
- Download instant client from Oracle
instantclient-basic-macos.x64-19.3.0.0.0dbru.zip
instantclient-sqlplus-macos.x64-19.3.0.0.0dbru.zip
instantclient-sdk-macos.x64-19.3.0.0.0dbru.zip
instantclient-jdbc-macos.x64-19.3.0.0.0dbru.zip
instantclient-odbc-macos.x64-19.3.0.0.0dbru.zip
- Set up .bash_profile
# Oracle instant client variables
export ORACLE_HOME=/usr/local/oracle/instantclient
export OCI_HOME=$ORACLE_HOME
export OCI_LIB_DIR=$OCI_HOME
export OCI_INCLUDE_DIR=$OCI_HOME/sdk/include
export NLS_LANG=AMERICAN_AMERICA.UTF8
export DYLD_LIBRARY_PATH=$OCI_LIB_DIR
export PATH=$ORACLE_HOME:$PATH
- Set up the
odbc.ini
file. You can find the location of theodbc.ini
file by runningodbcinst -j
. It will return something like this
unixODBC 2.3.7
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /Users/matt/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
Edit the file /usr/local/etc/odbc.ini
to look like
[oracle]
AggregateSQLType=FLOAT
Application Attributes=T
Attributes=W
BatchAutocommitMode=IfAllSuccessful
BindAsFLOAT=F
CacheBufferSize=20
CloseCursor=F
DisableDPM=F
DisableMTS=T
DisableRULEHint=T
Driver=/usr/local/oracle/instantclient/libsqora.dylib.19.1
DSN=oracle
EXECSchemaOpt=
EXECSyntax=T
Failover=T
FailoverDelay=10
FailoverRetryCount=10
FetchBufferSize=64000
ForceWCHAR=F
LobPrefetchSize=8192
Lobs=T
Longs=T
MaxLargeData=0
MaxTokenSize=8192
MetadataIdDefault=F
QueryTimeout=T
ResultSets=T
ServerName=****
SQLGetData extensions=F
SQLTranslateErrors=F
StatementCache=F
Translation DLL=
Translation Option=0
UseOCIDescribeAny=F
UserID = ****
Password = ****
- Copy 01_setup.sh into the downloads file. This should be the same place where you downloaded the instant client files. Here I am assuming you copied 01_setup.sh into a file called setup.sh in the Downloads folder. To run the file type
sudo ./setup.sh
Make sure you run this in the downloads folder!
-
Open RStudio
-
Make a new RScript with 04_connection_object.r. Once you install the packages odbc and dbi you can delete the two install commands. When you run this script you should not return any errors.
-
In RStudio make a new sql file using 05_pull.sql. If this is the first time you have used the preview feature, RStudio will need to download a package. It will prompt you for this. When you save the file pull.sql, RStudio will show the result. It should return the current time. If you click the preview button, RStudio will rerun the pull and the time should update. If it does, you are all set.
I can't thank you enough for this guide. I have spent DAYS trying to get oracle working and this was the guide that saved me!