Using built-in database functions in Ruby to call orcale database is more troublesome, but fortunately the Open Source of the East expansion is very good, we can use the open source components of ruby-oci8 to orcale database for a series of operations.
The installation method is not described in detail. For details, refer to http://ruby-oci8.rubyforge.org/en/installbinarypackage.html. The following describes how to operate the data warehouse:
Require 'ci8'
Conn = oci8.new (user_name, user_pwd, db_name)
Cursorw.conn.exe C ("select * from student where ID> 10 ″)
While R = cursor. Fetch ()
Arr = R. Join ()
End
Cursor. Close
Conn. Logoff
The code above allows you to query data from a database and save the query results in the ARR array.
It is very convenient to access the orcale database using oci8. First, use the oci8.new () method to establish a database connection, and then use the exec () method to execute SQL statements, such as select, updae, and delete, however, you must note that you must execute the Commit () method to submit changes after performing the update, delete, insert, and other operations. Otherwise, the changes will not take effect. The general process is:
Conn = oci8.new (user name, password, database name)
Conn.exe C (SQL statement)
Conn. Commit
Conn. Logoff
There are many other useful methods, please refer to http://ruby-oci8.rubyforge.org/en/api_OCI8.html for details