RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Ruby连接到oracle技巧分享

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

目前成都创新互联公司已为千余家的企业提供了网站建设、域名、网络空间、网站托管、企业网站设计、兰溪网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

我们可以使用OCI8库来实现Ruby连接到oracle ,它可以支持oracle8之后的版本:

  1. require 'oci8'   
  2. session = OCI8.new('user', 'password')   
  3. query = "SELECT TO_CHAR(SYSDATE, 
    'YYYY/MM/DD') FROM DUAL"   
  4. cursor = session.exec(query)   
  5. result = cursor.fetch       
  6. # Only one iteration inthis case   
  7. cursor.close   
  8. session.logoff 

下面是Ruby连接到oracle 查询的例子:

 
 
 
  1. session = OCI8.new("user","password")   
  2. query = "select * from people 
    where name = :name"   
  3. # One way...   
  4. session.exec(query,'John Smith')   
  5. # Another...   
  6. cursor = session.parse(query)   
  7. cursor.exec('John Smith')   
  8. # And another...   
  9. cursor = session.parse(query)   
  10. cursor.bind_param(':name','John Smith')
     # bind by name   
  11. cursor.exec   
  12. # And another.   
  13. cursor = session.parse(query)   
  14. cursor.bind_param(1,'John Smith')   
     # bind by position   
  15. cursor.exec  

以下是Ruby连接到oracle 的代码示例讲解。


分享名称:Ruby连接到oracle技巧分享
文章来源:http://www.jxjierui.cn/article/ccdhish.html