当前位置: 首页 > 工具软件 > ruby-oci8 > 使用案例 >

How To Install ruby-oci8 on Ubuntu Desktop 64bits

督烨赫
2023-12-01

Ruby-oci8 is the Oracle connector for Ruby, using this library your Ruby programs cancommunicate with the Oracle database.

If you have not installed Ruby yet on your machine, please refer to the Ubuntu package on thispost.

Install few additional Linux packages:

sudo apt-get install libaio-dev unzip

Create an Oracle folder:

sudo mkdir /opt/oracle

Go the Oracle website to download theInstant Client Basic and SDK for Linux 64 bits.
Download files in the Oracle folder you have created andunzip them:(下载的文件名可能有所差异)

cd /opt/oracle
unzip oracle-basic-11.zip
unzip oracle-sdk-11.zip

Once you have unzip the 2 zip files, go in the Instant Client folder and create a link for application that does not know Instant Client 11.

cd instantclient_11_2/
sudo ln -s libclntsh.so.11.1 libclntsh.so

Create the Oracle Instant Client system variable

export LD_LIBRARY_PATH=/opt/oracle/instantclient_11_2

Then, install ruby-oci8:

sudo env LD_LIBRARY_PATH=/opt/oracle/instantclient_11_2  /usr/local/bin/gem install ruby-oci8(在此之前记得设置oracle环境变量export ORACLE_HOME=/opt/oracle/app/oracle/product/11.2.0/dbhome_1)

Try to connect to the database, create a Ruby file for example sql.rb and copy/paste the following code:

require ‘rubygems’
require ‘oci8′
tnsnames = ‘(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = host_name_or_ip)(PORT = 1521)) (CONNECT_DATA = (SID = SID)))’
conn = OCI8.new(‘user’, ‘password’, tnsnames)
cursor = conn.exec(‘SELECT sysdate FROM dual’)
while r = cursor.fetch()
puts r.join(‘,’)
end
cursor.close
conn.logoff

And run it:

ruby sql.rb
Fri Sep 24 08:28:00 +0900 2010

Enjoy and have fun with Ruby and Oracle.


原帖链接 http://www.it-wikipedia.com/web/how-to-install-ruby-oci8-on-ubuntu-server.html

 类似资料:

相关阅读

相关文章

相关问答