Вопрос

I have an Oracle package with a stored procedure in it that is returning a table called prereq_list. The declaration of my data type being returned is:

TYPE prereq_list IS TABLE OF VW_PREREQ_SVC_CD%ROWTYPE;

The signature of my stored proc looks like this:

PROCEDURE GET_PREREQS (
site_id_in IN VARCHAR2,
rate_group_in IN VARCHAR2,
service_code_in IN VARCHAR2,
prereq_list_out out prereq_list);

I'm trying to call this stored procedure using Ruby and OCI8 which look like this:

cursor = Warehouse::Base.connection.raw_connection.parse("BEGIN codekeeper.get_prereqs(:site, :rate_grp, :svc_code, :prereqs); END;")
cursor.bind_param(':site', '9')
cursor.bind_param(':rate_grp','3990003')
cursor.bind_param(':svc_code','RPSTARZ')
cursor.bind_param(':prereqs', nil, OCI8::Cursor )
cursor.exec()
results_cursor = cursor[':prereqs'] 
cursor.close
while row = results_cursor.fetch()
  puts row.join(',')
end
results_cursor.close    

I know that my basic approach is sound. If I replace the output variable with a simple String or Number, I can get to whatever is output. That really isn't what I need though. I need to be able to return either a true cursor or at least an array of hashes.

Это было полезно?

Решение

This was definitely a case of not properly reading my own code. The prereq_list_out I'm returning is, go figure, NOT a ref cursor. It's a TABLE.

If you make get_reqs return a sys_refcursor instead of that custom type TABLE I'm using, and change the cursor.bind_param declaration to cursor.bind_param(':prereqs', OCI8::Cursor) the oci8 call to return a cursor as an output bind_param will work. A solid and complete example of doing this can be found here: https://blogs.oracle.com/opal/entry/casting_plsql_arrays_as_ref_cu although you'll need to read around the fact that the guy at oracle is trying to solve a slightly different problem. He's not worrying about returning a cursor, he just does it. His example is about trying to get values out of a PL SQL Array.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top