I'm running Node 8.9.4, Hapi 17.4, and Oracledb 2.2.
When attempting to call a stored procedure, I get the error "NJS-012: encountered invalid bind data type in parameter 2". Nothing I've been able to do seems to fix the issue. The code that calls the procedure is:
async function getSavedViews(req, h, server) {
let connection = await server.app.db.getConnection();
let bindVars = {
P_USER_NAME: req.payload.user_name,
P_CONTENT_TYPE: req.payload.content_type,
P_PROJECT_NUMBER: req.payload.project_number,
OP_GRID_TAB_TYP: { dir: server.app.db.BIND_OUT, type: server.app.db.ARRAY }
}
let res = server.methods.response();
try {
res.error = false;
res.msg = "Retrieved saved views.";
res.data = await connection.execute(
`BEGIN APPS.XXETA_GRID_USER_CONTEXT_PKG.EXTRACT_GRID_DETAILS(:P_USER_NAME, :P_CONTENT_TYPE, :P_PROJECT_NUMBER, :OP_GRID_TAB_TYP); END;`,
bindVars
);
} catch (err) {
server.app.logger.error(err.message);
res.error = true;
res.msg = err.message,
res.data = [];
}
return res;
}
The stored procedure is described as:
The error I get from my logger is: 2018-08-06 15:02:20 ERROR NJS-012: encountered invalid bind data type in parameter 2
Any help would be appreciated.
UPDATE:
The complex type that is the bound out variable looks like this...
CREATE OR REPLACE TYPE XXETA_GRID_CONTEXT_REC_TYP AS OBJECT
(
GRID_VIEW_ID NUMBER (15),
GRID_VIEW_NAME VARCHAR2 (240),
USER_NAME VARCHAR2 (30),
PROJECT_NUMBER VARCHAR2 (5)
)
Update 2019/08/28:
Node-oracledb added support for SQL object types and PL/SQL record types in v4 (released 2019/07/25). See this section of the doc for details: https://oracle.github.io/node-oracledb/doc/api.html#objects
Given the exact same objects as listed before, the following JavaScript can now be used to do the job with far fewer lines of code than before:
Previous answer:
Complex types are not currently supported. The out bind you have specified falls in this category. Until such types are directly supported, you'll need to add a bit of wrapper code to break the complex type into one or more simple types. I show an example of this here: https://jsao.io/2017/01/plsql-record-types-and-the-node-js-driver/
The goal in that post is to invoke a stored procedure which accepts an array of a custom record type. To invoke it, I first have to declare some simple array types to bind into. Then I can use those arrays to create the more complex array and invoke the procedure.
In your case, you'll need to do the reverse. In the PL/SQL block, declare a local variable of type APPS.XXETA_GRID_CONTEXT_TAB_TYP. Then, after the procedure is invoked, iterate over the array and use it to populate some simple arrays (VARCHAR2, NUMBER, or DATE) and used those as your out binds.
Update:
Provided you have the following objects:
The following Node.js code can invoke the stored procedure and get the values from the complex out parameter.
I hope that helps! Direct support for complex types is on the list of enhancements, just can't say when it will land.