Ruby连接到oracle技巧分享
Ruby语言作为一种新的开发编程语言,其具体使用方法还需要我们不断的去深入了解。在这篇文章中我们将会为大家详细介绍有关Ruby连接到oracle 的一些技巧。#t#

目前成都创新互联公司已为千余家的企业提供了网站建设、域名、网络空间、网站托管、企业网站设计、兰溪网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
我们可以使用OCI8库来实现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 的代码示例讲解。
分享名称:Ruby连接到oracle技巧分享
文章来源:http://www.jxjierui.cn/article/ccdhish.html


咨询
建站咨询
