Connection to Oracle Database from R Command Prompt

Oracle R Enterprise connects to an Oracle Database instance and creates Oracle R Enterprise objects and stores them in the database.
To use Oracle R Enterprise, you first connect to an Oracle Database instance as described in the following topics:
About Connecting to the Database

Step 1: Oracle R Enterprise client components connect an R session to an Oracle Database instance and the Oracle R Enterprise server components. The connection makes the data in a database schema available to the R user. It also makes the processing power, memory, and storage capacities of the database server available to the R session through the Oracle R Enterprise client interface.

We can do this by using the ore.connect() to connect to the schema in an oracle database instance. We can also check the status of the connection by giving the command ore.is.connected().

Click on the R icon on your desktop which must be previously installed in your system. This is the main screen for the R Command prompt. We are showing the basics from the R command prompt, but we can also use the IDE i.e. the RStudio.

r1

Step 2: To begin using Oracle R Enterprise, you first connect to a schema in an Oracle Database instance with the ore.connect function. Only one Oracle R Enterprise connection can exist at a time during an R session. If an R session is already connected to the database, then invoking ore.connect terminates the active connection before opening a new connection. Now we have with us the previously installed ORE package, if not then you can install packages using the install.packages(“package_name”) command, then we can load it to the R session we are connected to by the library() then hit the return key(Enter) and you can see the Packages.as follows:

 

r2r3

 

Step 3: Now we connect to the oracle database by giving the command ore.connect() as follows :
Here you can provide your credentials and then hit the return button on your keyboard. You can check the connection status by giving the command ore.is.connected and it returns to TRUE.

 

r4connected
Using the ore.connect and ore.disconnect Functions

To explicitly end the connection between an R session and the Oracle Database instance, invoke the ore.disconnect function. Oracle R Enterprise implicitly invokes ore.disconnect if you do either of the following:
Quit the R session.
Invoke ore.connect while an Oracle R Enterprise connection is already active.

When you disconnect the active connection, Oracle R Enterprise discards all Oracle R Enterprise objects that you have not explicitly saved in an Oracle R Enterprise datastore.
We can directly write the command ore.disconnect() to quit an R session. Then we can again check the status by ore.is.connected().

 

disconnected

Leave A Reply

Your email address will not be published. Required fields are marked *