ruby - 如何在 Ruby 中运行 Oracle 存储过程

标签 ruby oracle stored-procedures

我已获得 Oracle 数据库的读取权限,可以为我自己的数据库获取数据。 DBA 给了我一个存储过程,他向我保证这就是我所需要的,但我至今无法从 Ruby 运行它。

我安装了 ruby​​-oci8 gem 和 oracle 即时客户端。

这是我到目前为止所管理的。

require 'oci8'
conn = OCI8.new('user','pass','//remoteora1:1521/xxxx')
=> #<OCI8::RWHRUBY>
cursor = conn.parse("call REPOSITORY.GET_PMI_ADT( '722833', 'W', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)")
=> #<OCI8::Cursor:0x56f4d50>

这就是我卡住的地方。我有这个 OCI8::Cursor 对象,但我不知道如何处理它。它应该返回一大堆结果(空值在查询中),但我什么也没得到。使用和不使用参数运行 cursor.exec(虽然我不确定我需要什么参数)会给我错误。

cursor.exec 给出

OCIError: ORA-06553: PLS-:
ORA-06553: PLS-:
ORA-06553: PLS-:
ORA-06553: PLS-306: wrong number or typ
ORA-06553: PLS-306: wrong number or type of arguments in call to 'GET_PMI_ADT'
ORA-06553: PLS-306: wrong number or type of arguments in call to 'GET_PMI_ADT'
ORA-06553: PLS-306: wrong number or type of arguments in call to 'GET_PMI_ADT'
ORA-06553: PLS-306: wrong number or type of arguments in call to 'GET_PMI_ADT'
ORA-06553: PLS-306: wrong number or type of arguments in call to 'GET_PMI_ADT'
ORA-06553: PLS-306: wrong number or type of arguments in call to 'GET_PMI_ADT'
ORA-06553: PLS-306: wrong number or type of arguments in call to 'GET_PMI_ADT'

等...

cursor.fetch 给出

OCIError: ORA-24338: statement handle not executed

这里有人有什么想法吗?我完全无法理解。

此处为仍在观看的任何人更新。如果我将存储过程更改为

BEGIN REPOSITORY.GET_PMI_ADT( '722833', 'W', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); END;

我现在得到错误;

OCIERROR: ORA-06550: line 1, column 45:
PLS-00363: expression ' NULL' cannot be used as an assignment target

这是否确认存储过程不正确?有什么明显的办法可以纠正它吗?

最佳答案

这应该有帮助:

http://rubyforge.org/forum/forum.php?thread_id=11295&forum_id=1078

示例如下:

msi是IN变量状态,remaining_credit是OUT变量

cursor = conn.parse ('begin ROAMFLEX.GETMSISDNSTATUS(:msi, :status, :remaining_credit); end;')
cursor.bind_param(':msi', '250979923')
cursor.bind_param(':status', nil, String, 20)
cursor.bind_param(':remaining_credit', nil, String, 50)
cursor.exec()
puts cursor[':status']
puts cursor[':remaining_credit_amount']

关于ruby - 如何在 Ruby 中运行 Oracle 存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11608289/

相关文章:

ruby - 为什么关键字参数必须作为带有符号键的散列传递,而不是 Ruby 中的字符串键?

oracle - 替换最后一次出现的子字符串

mysql - 如果 MySQL 存储过程中的条件未正确评估

database - H2数据库写复杂存储过程

ruby - 如何化简分数为带分数

ruby-on-rails - Rails - 如何使用 "near"条件进行 Geocoder "where"查询?

javascript - Rails 5 - React.js 入门

sql - 如何同时选择 count(*) group by 和 select *?

java - 我的结果集只会打印第一行

asp.net-mvc - 如何从mvc3调用存储过程?