oracle 连接

一、linux
Sys.setenv(NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")

library(ROracle)
drv <- dbDriver("Oracle")
connect.string <- paste(
  "(DESCRIPTION=",
  "(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.30.12)(PORT=1521))",
  "(CONNECT_DATA=(SERVICE_NAME=JZDB1)))", sep = "")
con <- dbConnect(drv, username = "<>", password = "<>",
                 dbname = connect.string)
jzjl <- dbGetQuery(con, "select * from inoc_jzjl where rownum<1000")
et <- dbGetQuery(con,"select * from grda_et where rownum<1000")
dbDisconnect(con)
class(et)

#GBK转UTF-8
library(tidyverse)
library(magrittr)
et %<>%
  select_if(is.character) %>%
  map_df(~ iconv(.x,from="GBK",to="UTF-8"))

jzjl %<>%
  select_if(is.character) %>%
  map_df(~ iconv(.x,from = "GBK",to="UTF-8"))

二、windows
Sys.setenv(JAVA_HOME='F:\\jdk-11.0.1')
library(RJDBC)
library(tidyverse)
#drv <- JDBC("oracle.jdbc.OracleDriver",classPath="/usr/lib/oracle/18.3/client64/lib/ojdbc8.jar", " ")
drv <- JDBC(driverClass="oracle.jdbc.OracleDriver",
                   classPath="F:/plsql/instantclient_12_2/ojdbc8.jar")
conn <- dbConnect(drv,"jdbc:oracle:thin:@//192.168.30.12:1521/JZDB1",
                 "<>", "<>")

sql <- "select * from grda_et where rownum<100"
et <- dbGetQuery(conn,sql)
dbGetTables(conn)
dbDisconnect(conn)

评论

此博客中的热门博文

V2ray websocket(ws)+tls+nginx分流

Rstudio 使用代理