Learn R Programming

ROracle (version 0.3-3)

Oracle: Instantiate an Oracle client from the current R or S session

Description

This function creates and initializes an Oracle client from the current R/S session. It returns an object that allows you to connect to one or several Oracle servers.

Usage

Oracle(max.con = 10, fetch.default.rec = 500, force.reload = F)

Arguments

max.con
maximum number of connections that we intend to have open. This can be up to 10, a limit hard-coded in the current implementation.
fetch.default.rec
number of records to fetch at one time from the database. (The fetch method uses this number as a default.)
force.reload
should we reload (reinitialize) the client code? Setting this to TRUE allows you to change default settings. Notice that all connections should be closed before re-loading.

Value

  • An object OraManager that extends dbManager and dbObjectId. This object is used to create connections, using the function dbConnect, to one or several Oracle database engines.

Side Effects

The R/S client part of the database communication is initialized, but note that connecting to the database engine needs to be done through calls to dbConnect.

Oracle user authentication

In order to establish a connection to an Oracle server users need to provide a user name, a password, and possibly an ``Oracle SID'' (i.e., a database name); by default the Oracle SID is taken from the environment variable $ORACLE_SID. The function dbConnect allows authentication strings similar to the Oracle monitor SQL*Plus, namely, a string of any of the following forms:
  1. "user/passsword"
  2. "user/password@dbname"
  3. "/"(provided the Oracle server is set up to use the underlying operating system users and passwords);

References

See the Omega Project for Statistical Computing at http://www.omegahat.org for more details on the R/S database interface.

See the documentation at the Oracle Web site http://www.mysql.com for details.

Details

This object is a singleton, that is, on subsequent invocations it returns the same initialized object.

This implementation allows you to connect to multiple host servers and run multiple connections on each server simultaneously.

See Also

On database managers:

dbManager Oracle load unload

On connections, SQL statements and resultSets:

dbExecStatement dbExec fetch quickSQL

On transaction management:

commit rollback

On meta-data:

describe getVersion getDatabases getTables getFields getCurrentDatabase getTableIndices getException getStatement hasCompleted getRowCount getAffectedRows getNullOk getInfo

Examples

Run this code
## create a Oracle instance and create one connection.
m <- dbManager("Oracle")
con <- dbConnect(m, user = "opto", password="pure-light", db="oras")

## you can also use Oracle's user/password@dbname convention
con2 <- dbConnect(m, user = "opto/pure-light@oras")

## or if you have defined the ORACLE_SID shell variable
con3 <- dbConnect(m, user = "opto", password = "pure-light")

## clone an existing connection
w <- dbConnect(con)

## execute a statement and fetch its output in chunks of no more
## than 5000 rows at a time

rs <- dbExec(con, "select * from HTTP_ACCESS where IP_ADDRESS = '127.0.0.1'")

while(!hasCompleted(rs)){
   df <- fetch(rs, n = 5000)
   process(df)
}

hasCompleted(rs)
[1] TRUE
close(rs)      ## done with this query
close(con)     ## done with this connection

Run the code above in your browser using DataLab