# NOT RUN {
# }
# NOT RUN {
## Create an Oracle Database instance and create one connection on the
## same machine.
drv <- dbDriver("Oracle")
## Use username/password authentication.
con <- dbConnect(drv, username = "scott", password = "tiger")
## Run a SQL statement by creating first a resultSet object.
rs <- dbSendQuery(con, "select * from emp where deptno = 10")
## We now fetch records from the resultSet into a data.frame.
data <- fetch(rs) ## extract all rows
dim(data)
# }
# NOT RUN {
# }
# NOT RUN {
## Create an Oracle Database instance and create one connection to a
## remote database using the SID in the connect string.
drv <- dbDriver("Oracle")
## Refer to Oracle Database Net Services Administator's Guide for
## details on connect string specification.
host <- "myhost"
port <- 1521
sid <- "mysid"
connect.string <- paste(
"(DESCRIPTION=",
"(ADDRESS=(PROTOCOL=tcp)(HOST=", host, ")(PORT=", port, "))",
"(CONNECT_DATA=(SID=", sid, ")))", sep = "")
## Use username/password authentication.
con <- dbConnect(drv, username = "scott", password = "tiger",
dbname = connect.string)
## Run a SQL statement by creating first a resultSet object.
rs <- dbSendQuery(con, "select * from emp where deptno = 10")
## We now fetch records from the resultSet into a data.frame.
data <- fetch(rs) ## extract all rows
dim(data)
# }
# NOT RUN {
# }
# NOT RUN {
## Create an Oracle Database instance and create one connection to a
## remote database using the service name.
drv <- dbDriver("Oracle")
## Refer to Oracle Database Net Services Administator's Guide for
## details on connect string specification.
host <- "myhost"
port <- 1521
svc <- "mydb.example.com"
connect.string <- paste(
"(DESCRIPTION=",
"(ADDRESS=(PROTOCOL=tcp)(HOST=", host, ")(PORT=", port, "))",
"(CONNECT_DATA=(SERVICE_NAME=", svc, ")))", sep = "")
## Use username/password authentication.
con <- dbConnect(drv, username = "scott", password = "tiger",
dbname = connect.string)
## Run a SQL statement by creating first a resultSet object.
rs <- dbSendQuery(con, "select * from emp where deptno = 10")
## We now fetch records from the resultSet into a data.frame.
data <- fetch(rs) ## extract all rows
dim(data)
# }
# NOT RUN {
# }
# NOT RUN {
## Create an Oracle Database instance and create one connection.
drv <- dbDriver("Oracle")
## Use Oracle Wallet authentication.
con <- dbConnect(drv, username ="", password="",
dbname = "<wallet_connect_string>")
## Run a SQL statement by creating first a resultSet object.
rs <- dbSendQuery(con, "select * from emp where deptno = 10")
## We now fetch records from the resultSet into a data.frame.
data <- fetch(rs) ## extract all rows
dim(data)
# }
# NOT RUN {
# }
# NOT RUN {
## Create an Oracle Database instance and create one connection.
drv <- dbDriver("Oracle")
## Connect to a TimesTen IMDB instance using the easy connect
## naming method where SampleDb is a direct driver TimesTen DSN.
con <- dbConnect(drv, username ="scott", password="tiger",
dbname = "localhost/SampleDb:timesten_direct")
## Run a SQL statement by creating first a resultSet object.
rs <- dbSendQuery(con, "select * from dual")
## We now fetch records from the resultSet into a data.frame.
data <- fetch(rs) ## extract all rows
dim(data)
# }
# NOT RUN {
# }
# NOT RUN {
## Connect to an extproc (this assumes that the driver has already
## been initialized in the embedded R code by passing an external
## pointer representing the extproc context).
con <- dbConnect(Extproc())
## Run a SQL statement by creating first a resultSet object.
rs <- dbSendQuery(con, "select * from dual")
## We now fetch records from the resultSet into a data.frame.
data <- fetch(rs) ## extract all rows
dim(data)
# }
# NOT RUN {
# }
# NOT RUN {
## Create an Oracle Database instance and create one connection.
drv <- dbDriver("Oracle")
## Create connection with SYSDBA privileges.
con <- dbConnect(drv, username ="scott", password="tiger",
sysdba = TRUE)
## Run a SQL statement by creating first a resultSet object.
rs <- dbSendQuery(con, "select * from emp where deptno = 10")
## We now fetch records from the resultSet into a data.frame.
data <- fetch(rs) ## extract all rows
dim(data)
# }
# NOT RUN {
# }
# NOT RUN {
## Create an Oracle Database instance and create one connection.
drv <- dbDriver("Oracle")
## Use OS authentication as an example of external authentication
## Make sure that databse user exist to allow an OS authentication
## Create connection authenticated with external credentials.
con <- dbConnect(drv, username ="", password="",
external_credentials = TRUE)
## Above dbConnect() used OS credentials to connect with database.
## Run a SQL statement by creating first a resultSet object.
rs <- dbSendQuery(con, "select * from emp where deptno = 10")
## We now fetch records from the resultSet into a data.frame.
data <- fetch(rs) ## extract all rows
dim(data)
# }
Run the code above in your browser using DataLab