Back

Technologies:

javascriptjavascript
node.jsnode.js
avatar
Tolerim
a month ago

What is the meaning of the NJS-005 error message when attempting to execute many node-oracledb parameters?

Here’s the given paragraph with a revised version: While attempting to execute code, I received the "Error: NJS-005: invalid value for parameter 2." I have thoroughly researched the documentation and am certain my approach is not faulty. It is possible someone with an additional perspective could help identify the issue.

I am providing some context for my issue, as the platform is informing me that my question contains too much code and needs more details. Essentially, I am writing node code that should insert a bulk of data but is not functioning properly. I have included the error message and provided the corresponding code snippets for your reference. Please let me know if anything further is required to assist me. Thank you for your time.

const createContractItemDb = async (contractItems) => {
  console.log("createContractItemDb hit, payload: ", contractItems);
  let connection;
  try {
    connection = await oracledb.getConnection(connectionString);

    const data = [
      {
        salecontno: 10239,
        item_no: 349,
        qty: 2,
        item_price: 5,
        disc_percentage: null,
        disc_amount: null,
        priceafterdisc: null,
        total_price: null,
        rec_user: 42,
        upd_user: 42,
        comments: null,
      },
      {
        salecontno: 10239,
        item_no: 368,
        qty: 2,
        item_price: 5,
        disc_percentage: null,
        disc_amount: null,
        priceafterdisc: null,
        total_price: null,
        rec_user: 42,
        upd_user: 42,
        comments: null,
      },
    ];

    const sql = `INSERT INTO salecontractitems (
      salecontno,
      item_no,
      qty,
      item_price,
      disc_percentage,
      disc_amount,
      priceafterdisc,
      total_price,
      rec_user,
      upd_user,
      comments
     ) VALUES (
      :salecontno,
      :item_no,
      :qty,
      :item_price,
      :disc_percentage,
      :disc_amount,
      :priceafterdisc,
      :total_price,
      :rec_user,
      :upd_user,
      :comments
    )`;

    const options = {
      autoCommit: true,
    };

    const result = await connection.executeMany(sql,data,options);
    return result;
  } catch (err) {
    // console.error(err);
    return { error: err };
  } finally {
    if (connection) {
      try {
        await connection.close();
      } catch (err) {
        console.error(err);
      }
    }
  }
};

Answers(2)
avatar
Vogi
a month ago
Verified Answer
The error message you received "Error: NJS-005: invalid value for parameter 2" is related to queries without bind parameters. It seems like you are writing node code that should insert a bulk of data but is not functioning properly. You have included the error message and provided the corresponding code snippets for reference. However, I would need more information to assist you better. Could you please provide me with the following details: - What is the version of node-oracledb you are using? - What is the version of Oracle Database you are using? - What is the exact error message you are receiving? - Are there any other error messages that appear in the console? - Have you tried running your code with a single row insert instead of multiple rows? Please let me know if anything further is required to assist you.

Sources

NJS-005: invalid value for parameter2 with queries without bind parametersError: NJS-005: invalid value for parameter 2 #1281 - GithubError: NJS-005: invalid value for parameter 2 #1401 - Githubnode-oracledb executeMany Error: NJS-005: invalid value for parameter 2
avatar
Tolerim
a month ago
The error message "Error: NJS-005: invalid value for parameter 2" usually indicates an issue with one of the parameters being used in the Oracle database query. In this case, since the error is happening in the executeMany method call, it is likely related to the data parameter being passed. One possible cause for this error is that the data being passed is not in the correct format or is not being passed in the correct order. Double-check that the data being passed has the correct values in the correct order based on the order of the parameters in the SQL query. Another possibility is that the data being passed contains null or undefined values, which could cause issues with the query execution. In this case, you can try removing the null values from the data array or explicitly setting a default value for them before passing them to the query. It is also worth noting that the error message provided does not give much information about the root cause of the error. It may be helpful to enable more detailed error logging or try debugging the code to get additional information about what is causing the issue.
;