首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Ruby中运行Oracle存储过程

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

Stack Overflow用户
提问于 2012-07-23 15:45:07
回答 3查看 2.3K关注 0票数 1

我被授予了对Oracle数据库的读访问权限,以便为我自己的数据库获取数据。DBA给了我一个存储过程,他向我保证这是我所需要的一切,但是到目前为止,我还不能从Ruby运行它。

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

这是我到目前为止所做的事情。

代码语言:javascript
复制
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给出

代码语言:javascript
复制
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给出

代码语言:javascript
复制
OCIError: ORA-24338: statement handle not executed

有没有人有什么想法?我的情况超出了我的能力范围。

对于仍在观看的人来说,这里有一个最新消息。如果我将存储过程更改为

代码语言:javascript
复制
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;

我现在得到了错误;

代码语言:javascript
复制
OCIERROR: ORA-06550: line 1, column 45:
PLS-00363: expression ' NULL' cannot be used as an assignment target

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-03-25 19:40:25

这应该会有帮助:

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

示例如下:

msi处于in变量状态,remaining_credit为OUT变量

代码语言:javascript
复制
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']
票数 3
EN

Stack Overflow用户

发布于 2012-08-07 03:06:54

您收到的错误

代码语言:javascript
复制
   PLS-00363: expression ' NULL' cannot be used as an assignment target

意味着在存储过程中,一些参数被定义为in OUT,这意味着它们必须是变量。使用参数来保存返回值来指示过程是通过还是失败是很常见的,但更常见的是使用可以返回布尔值true/false来指示成功的函数。

您需要向DBA提供您得到的错误消息,并要求您所调用的过程的完整签名,该签名应该告诉您正在传递的变量是IN/OUT变量。任何IN只能传递一个常量或NULL,而那些OUT或IN OUT需要是变量,您可能需要根据在这些变量中返回的内容执行一些操作。

票数 1
EN

Stack Overflow用户

发布于 2015-11-10 23:15:48

代码语言:javascript
复制
# PL/SQL records or object type parameters should be passed as Hash
# test_full_name is procedure name in oracle
# p_employee holds parameter list 
#employee_id is first param defined in stored procedure

require 'ruby-plsql'

p_employee = { :employee_id => 1, :first_name => 'First', :last_name => 'Last', :hire_date => Time.local(2000,01,31) }
 plsql.test_full_name(p_employee)   #plsql should hold connection object
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11608289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档