Cursor bind variable INOUT not working properly
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 got a full code snippet handy?
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 The error behavior was tweaked in 1.1 but support is still pending.
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
@SergioSuarezDev this issue is still open. We'll update it if/when any code change is merged. Don't forget that PRs are welcome.
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 see my previous comment!
Support for cursor IN binds was merged to 5.0.0-dev in the master branch on GitHub.
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
Super!