resultset from PL/SQL storeprocedure
In an common scenario, we need get resultset from PL/SQL procedures using OUT parameters of type REF CURSOR.
var bindvars = {
o_cursor: { type: oracledb.<???>, dir : oracledb.BIND_OUT },
}
connection.execute("BEGIN GET_PARTS( :o_cursor ); END;",
bindvars,
function(err, result)
{
if (err) {
console.log('%s', err.message);
return;
}
console.log(result.rows);
});
But only scalar parameters in/out/inout are supported.
When you estimate support an scenario like this?
Very Thanks,
Show us the code! What is the definition of GET_PARTS? Is this a standard REFCURSOR?
The code like this:
TYPE T_CURSOR IS REF CURSOR;
PROCEDURE GET_PARTS(O_CURSOR OUT T_CURSOR) AS
BEGIN
OPEN O_CURSOR FOR SELECT * FROM PARTS;
END GET_PARTS;
Thanks, JM
Thank you
Or for an anonymous pl/sql block something like this:
var bindvars = {
o_cursor: { type: oracledb.<???>, dir : oracledb.BIND_OUT },
}
connection.execute(sql, bindvars, function(err, result) {
if (err) {
console.log('%s', err.message);
return;
}
console.log(result.rows);
});
sql variable set to:
DECLARE
l_employee employees%ROWTYPE;
BEGIN
SELECT *
INTO l_employee
FROM employees
WHERE employee_id = 138;
:o_cursor := l_employee;
END;
For returning query results, 12c has Implicit Result Sets, so there potentially wouldn't need to be a bind variable. Some info on how this was implemented in PHP OCI8 is in http://php.net/manual/en/function.oci-fetch-array.php The node-oracledb design is TBD; I'm interested to hear your design thoughts.
Explicit result sets from procedures are absolutely essential for everybody who puts the most of the logic into the Oracle database like I do. And developers using mac os cannot go 12c.
@richlim thanks for your "vote" on this feature.
This is how I access 12c DB on OS X: https://blogs.oracle.com/opal/entry/the_easiest_way_to_enable
@cjbj thank you for you "advice". You suggest port forwarding to a VM, I run node on the a box supporting 12c. You suggest implicit RS, I think about about nearly any package's procedure I wrote relaying on implicit result set. A driver without the support of them is no option for me and possibly many others.
@richlim apologies for any confusion. IRS would be in addition to REF CURSOR support.
@cjbj I am very glad to hear that! I hope you will implement it soon. (Is probably much more important than lob support :)
@cjbj Any idea when we can expect a release containing this issue. The driver has all the features we require except this one and for that reason we forced to use other ways to access the oracle db. Just a ruff expectation would be great to hear !!..
@shuuke I really don't have an ETA on this.
@cjbj Can you hazard an ETA on this issue yet?
@buto No. I'd be interested to hear more about your intended use.
Thank you for you quick response. let me know If the way I am answering this isn't responsive to your question.
In my shop I always create a top-level package. This top-level package is placed in a schema that only has CONNECT and EXECUTE privs. This is to prevent sql injection.
here is a typical example
CREATE OR REPLACE PACKAGE song_mgr IS PROCEDURE get_details( p_org_id IN song_writer.org_id%TYPE, p_details IN OUT SYS_REFCURSOR, p_retcode OUT NUMBER ); END; / The SYS_REFCURSOR might be loaded by something simple like OPEN p_details FOR SELECT users.id AS usr_id, users.name AS usr_name FROM users WHERE users.org_id = p_org_id;
Or, for complex queries, I often load-up a nested table with data and select that into the SYS_REFCURSOR. This is more complicated and depends on creating object types in the DB and other steps. If the nest table technique is interesting I can show a toy example of how I go about that.
@Buto Thanks for the info. I could keep asking questions until I annoyed you! One quick one: do you ever return large sets of rows?
uh, how many rows do you regard as a "large set"?
For us, about 250 rows is our max
Also, don't worry about annoying me. You're just trying to find out what my standard practices are
@buto I want to make sure we are heading in the right direction.