技巧大讲堂之Ruby调用Oracle存储过程
Ruby语言作为一中简单的编程语言被我们广泛的运用。在操作数据库方面更是能够充分体现其特点。在这里我们就为大家介绍Ruby调用Oracle存储过程的相关技巧。
Ruby调用Oracle存储过程1.首先创建Oracle存储过程test:
- SQL> CREATE OR REPLACE PROCEDURE
test(p1 in varchar2,p2 out varchar2 ) is - 2 BEGIN
- 3 select p1||' PROCEDURE EXECUTED!
' into p2 from dual ; - 4 end;
- 5 /
- Procedure created
Ruby调用Oracle存储过程2.再写Ruby脚本,调用存储过程test,脚本内容如下,将脚本保存为:Call_proc_test.rb:
require 'dbi' db_read_str = 'BEGIN test(?, ?); END;' dbh = DBI.connect('DBI:OCI8:TNSDBNAME' , 'username', 'password') sth_db = dbh.prepare(db_read_str) sth_db.bind_param(1, 'test:',''*50) # allow for up to 50 chars sth_db.bind_param(2, ' ' * 100) # allow for up to 100 chars sth_db.execute str = sth_db.func(:bind_value, 2) puts str dbh.disconnect
Ruby调用Oracle存储过程3.检查Ruby语法错误:
C:\>ruby -cw Call_proc_test.rb Syntax OK C:\>
Ruby调用Oracle存储过程4.最后执行Ruby脚本:
相关推荐
Omega 2020-08-16
zjyzz 2020-08-16
minggehenhao 2020-07-28
zhaojp0 2020-06-27
zjuwangleicn 2020-06-25
wenjieyatou 2020-06-17
liaomingwu 2020-06-16
hungzz 2020-06-16
muzirigel 2020-06-14
gsmfan 2020-06-14
ncomoon 2020-06-14
xiaobaif 2020-06-13
Rain 2020-06-12
hanshangzhi 2020-06-12
talkingDB 2020-06-12
IBMRational 2020-06-09
snowguy 2020-06-01