考虑到使用R直接连接oracle对与读取数据具有较高的便利性,对此进行尝试使用ROracle进行连接。
1.下载Rtool
2.设置环境变量(注意不要覆盖)
Set OCI_LIB32 = C:\instantclient_11_2
Set path = C:\instantclient_11_2\sdk;D:\R-3.3.2\R\bin; C:\Rtools\gcc-4.6.3\bin; C:\Rtools\bin;
3.安装R_package
install.packages("DBI")
install.packages("ROracle")
4.加载包-连接数据库
library(DBI)
library(ROracle)
drv <-dbDriver("Oracle")
connect.tns <-"(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ****)(PORT =****)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = *****)(INSTANCE_NAME = **)))"
conn <-dbConnect(drv,username="***",password="***",dbname = connect.tns)
5.测试
test <-dbSendQuery(conn,"select 1,2,3 from dual")
data <-fetch(test)
data
得到以下结果,目前看来oracle是连接成功了