# NOT RUN {
# }
# NOT RUN {
## create a Oracle instance and create one connection.
ora <- Oracle() ## or dbDriver("Oracle")
con <- dbConnect(ora, username = "scott", password = "tiger",
dbname = "inst1")
## if you are connecting to a local database
con <- dbConnect(ora, username = "scott", password = "tiger")
## execute a statement and fetch its output in chunks of no more
## than 5000 rows at a time
rs <- dbSendQuery(con, "select * from emp where deptno = 10")
while (!dbHasCompleted(rs)) {
df <- fetch(rs, n = 5000)
## process df
}
dbClearResult(rs) ## done with this query
## execute and fetch a statement with bind data
df <- dbGetQuery(con, "select * from emp where deptno = :1",
data = data.frame(depno = 10))
## create a copy of emp table
dbGetQuery(con, "create table foo as select * from emp")
## execute and bind an INSERT statement
my.data = data.frame(empno = c(8001, 8002), ename = c('MUKHIN', 'ABOYOUN'))
more.data = data.frame(empno = c(8003), ename = c('JAMES'))
rs <- dbSendQuery(con, "insert into foo (empno, ename) values (:1, :2)",
data = my.data)
## execute with more data
execute(rs, data = more.data)
dbClearResult(rs) ## done with this query
## ok, everything looks fine
dbCommit(con)
## a concise description of the driver
summary(ora)
## done with this connection
dbDisconnect(con)
# }
Run the code above in your browser using DataLab