Install RODBC with Oracle 12c ODBC in Ubuntu 14.04 64-bit

1、安装 Oracle Instant Cilent

sudo alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
sudo alien -i oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
sudo alien -i oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
sudo alien -i oracle-instantclient12.1-odbc-12.1.0.2.0-1.x86_64.rpm

2、sudo gedit /etc/ld.so.conf.d/oracle.conf
添加  /usr/lib/oracle/12.1/client64/lib
sudo ldconfig

# 导致不能正常启动
# sudo gedit  /etc/profile.d/oracle.sh
# 添加 export ORACLE_HOME= /usr/lib/oracle/12.1/client64

3、安装 unixodbc
sudo apt-get install unixodc
检查64-bit unixodbc

which isql
file <the output above>

结果类似
ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID

4、配置连接
sudo gedit /etc/odbc.ini
添加
[MYORACLEDSN]
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
CloseCursor = F
DisableDPM = F
DisableMTS = T
Driver = Oracle
EXECSchemaOpt =
EXECSyntax = T
Failover = T
FailoverDelay = 10
FailoverRetryCount = 10
FetchBufferSize = 64000
ForceWCHAR = F
Lobs = T
Longs = T
MetadataIdDefault = F
QueryTimeout = T
ResultSets = T
ServerName = //10.112.0.6:1521/orcl
SQLGetData extensions = F
Translation DLL =
Translation Option = 0
UserName = "gssvac"
Password = "gssvac"

sudo gedit  /etc/odbcinst.ini
添加
[Oracle]
Description = Oracle ODBC Connection
Driver = /usr/lib/oracle/12.1/client64/lib/libsqora.so.12.1
Setup =
FileUsage =
CPTimeout =
CPReuse =

5、 测试
isql MYORACLEDSN gssvac gssvac

可能出现问题
ldd /usr/lib/oracle/12.1/client64/lib/libsqora.so.12.1

出现
libodbcinst.so.2 => not found
sudo updatedb
locate libodbcinst
结果
/usr/lib/x86_64-linux-gnu/libodbcinst.so.1
/usr/lib/x86_64-linux-gnu/libodbcinst.so.1.0.0

解决
sudo ln -s /usr/lib/x86_64-linux-gnu/libodbcinst.so.1 /usr/lib/libodbcinst.so.2


library(RODBC)
channel <- odbcConnect("MYORACLEDSN",uid="gssvac",pwd="gssvac")
tb_zyf <- sqlQuery(channel,'SELECT * FROM sys_log')
odbcClose(channel)

评论

此博客中的热门博文

V2ray websocket(ws)+tls+nginx分流

Rstudio 使用代理