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

Cursor bind variable INOUT not working properly

Open nethoncho opened this issue 11 years ago • 10 comments

node-oracledb version 0.7 When using a direction of BIND_INOUT on a cursor defined as IN OUT the following exception is thrown

PLS-00306: wrong number or types of arguments in call to 'EMPLOYEES_R'

To work around this issue I switched the direction to BIND_OUT

PROCEDURE employees_r(
p_details    IN OUT  hr_child.empl_details_refcur_t,
p_retcode    OUT     NUMBER
);

Dose not work bindVars.cursor = { type: oracledb.CURSOR, dir : oracledb.BIND_INOUT };

Works bindVars.cursor = { type: oracledb.CURSOR, dir : oracledb.BIND_OUT };

nethoncho avatar Aug 17 '15 01:08 nethoncho

@nethoncho got a full code snippet handy?

cjbj avatar Aug 17 '15 02:08 cjbj

Stored Procedure

CREATE OR REPLACE PROCEDURE get_emp_rs_inout (p_sal IN NUMBER, p_recordset IN OUT SYS_REFCURSOR)
AS
BEGIN
  OPEN p_recordset FOR
    SELECT first_name, salary, hire_date
    FROM   employees
    WHERE  salary > p_sal;
END;
/
SHOW ERRORS

Node app

var oracledb = require('oracledb');
var dbConfig = require('./dbconfig.js');

var numRows = 10;  // number of rows to return from each call to getRows()

oracledb.getConnection(
  {
    user          : dbConfig.user,
    password      : dbConfig.password,
    connectString : dbConfig.connectString
  },
  function(err, connection)
  {
    if (err) { console.error(err.message); return; }
    var bindvars = {
      sal:  12000,
      // p_recordset IN OUT SYS_REFCURSOR
      // works with BIND_OUT, fails with BIND_INOUT
      cursor:  { type: oracledb.CURSOR, dir : oracledb.BIND_INOUT }
    }
    connection.execute(
      "BEGIN get_emp_rs_inout(:sal, :cursor); END;",
      bindvars,
      function(err, result)
      {
        if (err) {
          console.error(err.message);
          doRelease(connection);
          return;
        }
        console.log(result.outBinds.cursor.metaData);
        fetchRowsFromRS(connection, result.outBinds.cursor, numRows);
      });
  });

function fetchRowsFromRS(connection, resultSet, numRows)
{
  resultSet.getRows( // get numRows rows
    numRows,
    function (err, rows)
    {
      if (err) {
        console.log(err);
        doClose(connection, resultSet); // always close the result set
      } else if (rows.length == 0) {    // no rows, or no more rows
        doClose(connection, resultSet); // always close the result set
      } else if (rows.length > 0) {
        console.log("fetchRowsFromRS(): Got " + rows.length + " rows");
        console.log(rows);
        fetchRowsFromRS(connection, resultSet, numRows);
      }
    });
}
function doRelease(connection)
{
  connection.release(
    function(err)
    {
      if (err) { console.error(err.message); }
    });
}

function doClose(connection, resultSet)
{
  resultSet.close(
    function(err)
    {
      if (err) { console.error(err.message); }
      doRelease(connection);
    });
}

nethoncho avatar Aug 17 '15 03:08 nethoncho

@nethoncho The error behavior was tweaked in 1.1 but support is still pending.

cjbj avatar Sep 03 '15 10:09 cjbj

having similar error:

error: "NJS-007: invalid value for "type" in parameter 1",

conexion.execute( "BEGIN B2B4Milena.dameAlmacenes(:laEntidad, :tabla); END;", { laEntidad: 1, tabla: { type: oracledb.CURSOR, dir : oracledb.BIND_INOUT } }, { outFormat: oracledb.OBJECT //Devolvemos el resultado en un objeto

SergioSuarezGil avatar May 13 '18 10:05 SergioSuarezGil

@SergioSuarezDev this issue is still open. We'll update it if/when any code change is merged. Don't forget that PRs are welcome.

cjbj avatar May 13 '18 23:05 cjbj

Getting Error executing query Error: NJS-007: invalid value for "type" in parameter 1 cursor: {type: oracledb.CURSOR, dir: oracledb.BIND_INOUT},

Did someone resolve this yet ?

chahidarid avatar Sep 19 '18 17:09 chahidarid

@chahidarid see my previous comment!

cjbj avatar Sep 19 '18 21:09 cjbj

Support for cursor IN binds was merged to 5.0.0-dev in the master branch on GitHub.

cjbj avatar Jun 12 '20 22:06 cjbj

Node-oracledb 5.0 is out. In the cases when a query returns a cursor and you want to bind it to pass back IN, you will want to set the prefetchRows attribute to 0. See the bottom of https://oracle.github.io/node-oracledb/doc/api.html#rowfetching

cjbj avatar Jun 29 '20 02:06 cjbj

Super!

SergioSuarezGil avatar Jul 01 '20 15:07 SergioSuarezGil