Ruby calls the orcale Database

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.