node-oracledb icon indicating copy to clipboard operation
node-oracledb copied to clipboard

resultset from PL/SQL storeprocedure

Open jmptrader opened this issue 11 years ago • 27 comments

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,

jmptrader avatar Jan 21 '15 18:01 jmptrader

Show us the code! What is the definition of GET_PARTS? Is this a standard REFCURSOR?

cjbj avatar Jan 21 '15 20:01 cjbj

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

jmptrader avatar Jan 22 '15 00:01 jmptrader

Thank you

cjbj avatar Jan 25 '15 18:01 cjbj

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; 

bchr02 avatar Feb 09 '15 17:02 bchr02

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.

cjbj avatar Feb 09 '15 19:02 cjbj

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 avatar Mar 24 '15 18:03 richlim

@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 avatar Mar 24 '15 19:03 cjbj

@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 avatar Mar 24 '15 20:03 richlim

@richlim apologies for any confusion. IRS would be in addition to REF CURSOR support.

cjbj avatar Mar 24 '15 20:03 cjbj

@cjbj I am very glad to hear that! I hope you will implement it soon. (Is probably much more important than lob support :)

richlim avatar Mar 24 '15 20:03 richlim

@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 avatar Mar 26 '15 08:03 shuuke

@shuuke I really don't have an ETA on this.

cjbj avatar Mar 26 '15 21:03 cjbj

@cjbj Can you hazard an ETA on this issue yet?

Buto avatar Apr 18 '15 22:04 Buto

@buto No. I'd be interested to hear more about your intended use.

cjbj avatar Apr 18 '15 22:04 cjbj

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 avatar Apr 18 '15 23:04 Buto

@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?

cjbj avatar Apr 19 '15 00:04 cjbj

uh, how many rows do you regard as a "large set"?

Buto avatar Apr 19 '15 00:04 Buto

For us, about 250 rows is our max

Buto avatar Apr 19 '15 00:04 Buto

Also, don't worry about annoying me. You're just trying to find out what my standard practices are

Buto avatar Apr 19 '15 00:04 Buto

@buto I want to make sure we are heading in the right direction.

cjbj avatar Apr 19 '15 00:04 cjbj