Ruby连接到oracle技巧分享

开发 开发工具
作为一个刚刚学习Ruby语言的朋友来说,对于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 的代码示例讲解。

责任编辑:曹凯 来源: ddvip.com
相关推荐

2009-12-15 18:15:24

Ruby连接到LDAP

2009-12-15 10:23:23

Ruby应用技巧

2009-12-18 10:47:16

Ruby装饰模式

2009-12-16 10:10:16

Ruby打开关闭文件

2009-12-17 10:18:17

Ruby创建构造器

2009-12-18 14:10:29

Ruby访问剪贴板

2009-12-16 11:04:51

Ruby操作文件权限

2017-06-13 10:30:20

oracle连接命名

2009-12-16 15:46:41

Ruby on rai

2009-12-16 10:49:42

Ruby操作二进制文件

2009-12-17 18:04:59

Ruby调用Oracl

2009-12-15 18:03:46

Ruby连接数据库

2009-12-14 09:33:04

Ruby安装

2009-12-18 17:01:37

Ruby基础代码

2009-12-16 16:37:59

Ruby on Rai

2009-12-14 15:30:43

安装Ruby on R

2009-12-14 18:23:38

Ruby DSL测试

2009-12-16 15:23:33

Ruby on rai

2009-12-18 17:24:12

Ruby配置Mysql

2009-12-15 14:51:50

Ruby继承
点赞
收藏

51CTO技术栈公众号