Ruby - Oci8 - 行类型调用函数不起作用

Ruby - Oci8 - Call funtion with rowtype not working

我有这样一个 oracle 函数:

CREATE OR REPLACE FUNCTION MY_FUNCTION (MY_ID IN VARCHAR2) 
RETURN vendedor%rowtype AS 
    res vendedor%rowtype; 
BEGIN  
    select * into res
    from vendedor
    where id = MY_ID;    
    return res;  
END MY_FUNCTION;

我想使用 oci8 gem 从我的 ruby 代码中调用此函数。这是我的 ruby 代码:

connectString = ENV['DB_CONNECTION']
conn = OCI8.new(connectString)
cursor = conn.parse ('begin :ret := MY_FUNCTION(:MY_ID); end;') 
cursor.bind_param(':MY_ID', '123', String)
cursor.bind_param(':ret', nil, OCI8::RAW) # This is the question
cursor.exec()
result = cursor[':ret']
cursor.close
conn.logoff

:ret变量的参数绑定类型是什么?

执行此代码抛出此错误:

ORA-06550: line 1, column 15: PLS-00382: expression is of wrong type ORA-06550: line 1, 
column 7: PL/SQL: Statement ignored

正在替换 cursor.bind_param(':ret', nil, OCI8::RAW)

cursor.bind_param(':ret', OCI8::Cursor) 会成功,

但您需要将函数转换为

CREATE OR REPLACE FUNCTION MY_FUNCTION (MY_ID IN VARCHAR2) RETURN sys_refcursor AS 
    res sys_refcursor; 
BEGIN  
    open res for
      select *
        from vendedor
          where id = MY_ID;    
    return res;  
END MY_FUNCTION;

准备returnsys_refcursor类型

要在 ruby 代码中获取结果:

result = cursor[':ret']
while r = result.fetch_hash
    retFinal = r
end

retFinal 变量有游标的最后结果