## 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)
## 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)
## 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)
## 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)
## 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)
## 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)
## 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)
## 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