在 R(并使用 ROracle)中,我如何成功地从我的数据库中提取数据?

In R (and using ROracle), how do I successfully pull in data from my database?

在 R(并使用 ROracle)中,我如何成功地从我的数据库中提取数据?看起来一切正常,但它没有从我的数据库中提供我的 table。

我有以下代码:


#set path to oracle client info
Sys.setenv(OCI_LIB64="C:-------\instantclient_19_3")

#set path to oracle product(original) info
Sys.setenv(OCI_INC="C:------11.2.0\client_3\oci\include")

#self-explanatory
install.packages('ROracle')

#Add any requiredlibraries:
   install.packages("tidyverse")
   install.packages("dplyr")
   install.packages("ROracle")
---

######################   LOAD THE LIBRARIES    ############################       
#This first block loads the libraries and deletes objects from the work. Instructions for installing the ROracle library can be found at http://cran.us.r-project.org/web/packages/ROracle/INSTALL.
library(tidyverse)
library(ROracle)
library(dplyr)


######################   CLEAR THE WORKSPACE  ############################   
# Clear the workspace
rm(list=ls())

######################   SET THE WORKING DIRECTORY ############################      

setwd("G:\----17_Annual_Averages_R")


######################   READ DATA IN FROM ORACLE   ############################
# Set this switch to true to read the data from the DB
READ_FROM_DB = TRUE

if (READ_FROM_DB)
{
  USER_NAME <- "WATER" ###Add your username
  PASSWORD <- "AQUA" ###Add your password
  # Create the connection string
  host <- "-------.gov"
  port <- ----
  sid <- "-----"
  connect.string <- paste(
    "(DESCRIPTION=",
    "(ADDRESS=(PROTOCOL=tcp)(HOST=",
    host,
    ")(PORT=",
    port,
    "))",
   "(CONNECT_DATA=(SID=",
    sid,
    ")))",
    sep = ""
  )
}

  # Load the driver
  drv <- dbDriver("Oracle")

  # Create the connection
  con <-  dbConnect(drv, USER_NAME, PASSWORD, dbname = connect.string)


  # Read the table
 rs <- dbSendQuery(con, "SELECT * FROM
WQ_VTSSS
WHERE site_id = 'PAIN'
")

当我 运行 所有这些时,它说我有数据,rs,但它说这是一个正式的 class OraResult 并且看起来像这样:

我哪里错了?

原来我忘记了从结果集中提取行的重要步骤(这不在我收到的说明中,而是在 ROracle.pdf 安装文件中)

这是我遗漏的步骤:


  ## We now fetch records from the resultSet into a data.frame.
data <- fetch(rs) ## extract all rows
dim(data)