Ruby連接到oracle技巧分享
作者:佚名
作為一個剛剛學(xué)習(xí)Ruby語言的朋友來說,對于Ruby連接到oracle的方法技巧還是比較陌生的。希望通過本文的介紹大家可以充分掌握這一技巧應(yīng)用。
Ruby語言作為一種新的開發(fā)編程語言,其具體使用方法還需要我們不斷的去深入了解。在這篇文章中我們將會為大家詳細(xì)介紹有關(guān)Ruby連接到oracle 的一些技巧。#t#
我們可以使用OCI8庫來實現(xiàn)Ruby連接到oracle ,它可以支持oracle8之后的版本:
- require 'oci8'
- session = OCI8.new('user', 'password')
- query = "SELECT TO_CHAR(SYSDATE,
'YYYY/MM/DD') FROM DUAL" - cursor = session.exec(query)
- result = cursor.fetch
- # Only one iteration inthis case
- cursor.close
- session.logoff
下面是Ruby連接到oracle 查詢的例子:
- session = OCI8.new("user","password")
- query = "select * from people
where name = :name"- # One way...
- session.exec(query,'John Smith')
- # Another...
- cursor = session.parse(query)
- cursor.exec('John Smith')
- # And another...
- cursor = session.parse(query)
- cursor.bind_param(':name','John Smith')
# bind by name- cursor.exec
- # And another.
- cursor = session.parse(query)
- cursor.bind_param(1,'John Smith')
# bind by position- cursor.exec
以下是Ruby連接到oracle 的代碼示例講解。
責(zé)任編輯:曹凱
來源:
ddvip.com