Node-oracledb: How can I solve the NJS error: 012, what is the correct way to add the date?

Created on 25 Jul 2019  路  4Comments  路  Source: oracle/node-oracledb

I want to execute the procedure from nodejs but when passing the parameters it gives me the following error:
Error: NJS-012: encountered invalid bind data type in parameter 2

Here is the image of the structure of the procedure in my database:
PROCEDURE Proc_Genctabalcons(Idtfechai DATE, Idtfechaf DATE, Inucliente NUMBER, Inunodo NUMBER, Inupunto NUMBER, Isbuser VARCHAR2, Isbterm VARCHAR2, Isbopc VARCHAR2, Onuerror OUT INTEGER, Osberror OUT VARCHAR2);

this is the code i'm running:


params = {
    Idtfechai: {value:  new Date('24/07/2019'), type : oracledb.DATE} ,
    Idtfechaf: {value: new Date('24/07/2019'), type: oracledb.DATE},
    Inucliente: -1 ,
    Inunodo: -1,
    Inupunto: -1,
    Isbuser: "MIGRACION",
    Isbterm: "MIGRACION",
    Isbopc: "MIGRACION",
    Onuerror: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT},
    Onuerror: { type: oracledb.DB_TYPE_VARCHAR, dir: oracledb.BIND_OUT},

};

result = await connection.execute(sql, params);
process.platform = win32,
process.version = v10.15.3,
process.arch = x64
require('oracledb') = oracledb": "^3.1.2"

Database: Oracle 11

Thanks.

question

All 4 comments

The last two entries in your params seem to have an identical property names. Is that intentional?

@cristian-programmer There are several issues going on here:

  • You need to specify val not value for the dates
  • The date format doesn't work, you need year-month-day
  • You have a duplicate property name (as @anthony-tuininga pointed out)
  • The reference to oracledb.DB_TYPE_VARCHAR should be oracledb.STRING

Because the first two dates are simple in binds, you don't need the object format. Here's a params object that should work for you:

    const params = {
        Idtfechai: new Date('2019-07-24'),
        Idtfechaf: new Date('2019-07-24'),
        Inucliente: -1 ,
        Inunodo: -1,
        Inupunto: -1,
        Isbuser: "MIGRACION",
        Isbterm: "MIGRACION",
        Isbopc: "MIGRACION",
        Onuerror: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT},
        Osberror: { type: oracledb.STRING, dir: oracledb.BIND_OUT},

    };

@anthony-tuininga
yeah , you're right, the last property is duplicated is {.., Osberror: {type: oracledb.STRING, dir: oracledb.BIND_OUT}}

very thanks!.

@dmcghan
Thank you very much for the help and it worked, and I also had a property repeated.

Was this page helpful?
0 / 5 - 0 ratings