Node-oracledb: Node JS Error: NJS-009: invalid number of parameters

Created on 13 Sep 2019  路  3Comments  路  Source: oracle/node-oracledb

Database ver : 12.1.0.2.0
node ver : v10.15.1

Please let me know the syntax if I want to bind more than 1 parameter

Invocation
node ../ReqdetSql_2.js "61486 20003"

===================== ERROR ============================
`
$ node ../ReqdetSql_2.js "61486 20003"
/orpppmd1/ppmapp/ohs11119/nodejs/node_modules/oracledb/lib/util.js:159
throw new Error(getErrorMessage(errorCode, messageArg1));
^

Error: NJS-009: invalid number of parameters
at Object.assert (/orpppmd1/ppmapp/ohs11119/nodejs/node_modules/oracledb/lib/util.js:159:11)
at Connection.execute (/orpppmd1/ppmapp/ohs11119/nodejs/node_modules/oracledb/lib/connection.js:130:12)
at Connection.execute (/orpppmd1/ppmapp/ohs11119/nodejs/node_modules/oracledb/lib/util.js:178:19)
at /orpppmd1/ppmapp/ohs11119/websrvr/instances/instance1/config/OHS/ohs1/cgi-bin/cprog/ReqdetSql_2.js:35:16
at /orpppmd1/ppmapp/ohs11119/nodejs/node_modules/oracledb/lib/oracledb.js:255:7
$
`
===================== End of error ============================

================== Code Start of JS file ==========================

var oracledb = require('oracledb');
var dbConfig = require('/orpppmd1/ppmapp/ohs11119/websrvr/instances/instance1/config/OHS/ohs1/htdocs/custrep/release/nodehtml/dbconfig.js');
var args0 = process.argv[1];
var args1 = process.argv[2];
var args2 = process.argv[3];
var args3 = process.argv[4];
var args4 = process.argv[5];

// console.log('val of args0 ' + args0);  
// console.log('val of args1 ' + args1);  
// console.log('val of args2 ' + args2);  
// console.log('val of args3 ' + args3);  
// console.log('val of args4 ' + args4);  

// Get a non-pooled connection
oracledb.getConnection(
  {
    user          : dbConfig.user,
    password      : dbConfig.password,
    connectString : dbConfig.connectString
  },
  function(err, connection) {
    if (err) {
      console.error(err.message);
      return;
    }
    connection.execute(
      // The statement to execute

         select 
         request_id,
         NVL(user_name,'-') c1,
         NVL(start_date,'-')  c2,
         NVL(compl_date,'-')  c3,
         NVL(running_for_min,0)  c4,
         NVL(phase_code_meaning,'-') c5,
         NVL(status_meaning,'-') c6,
         NVL(logfile_name,'-')  c7,
         NVL(outfile_name,'-') c8,
         NVL(responsibility_name,'-')  c9
        from 
        ( select * from CONC_REQ_Q_V r  
           where 
            r.phase_code = 'C'
            and r.program_id = :b 
            and r.application_id = :c
            order by r.start_date desc 
        ) sql_1
        where rownum < 25   ,

       [args1],
       [args2],

      { maxRows: 1000

      },

      // The callback function handles the SQL execution results
      function(err, result) {
        if (err) {
          console.error(err.message);
          doRelease(connection);
          return;
        }

        console.log(result.rows);     

      });
  });

// Note: connections should always be released when not needed
function doRelease(connection) {
  connection.close(
    function(err) {
      if (err) {
        console.error(err.message);
      }
    });
}

===================== End of JS file ==========================

question

All 3 comments

Note: If I hardcode the parameters it works fine.
I am just missing the binding syntax.

@cheslyn Please review the correct way to display code on GitHub with markdown: https://help.github.com/en/articles/creating-and-highlighting-code-blocks

You are trying to pass arguments as two separate arrays. You should use one array with multiple values: [args1, args2].

Alternatively, you can pass an object with multiple properties (positional notation vs named notation). See this section of the doc for more info and examples: https://oracle.github.io/node-oracledb/doc/api.html#bind

@dmcghan
Thanks a lot. It worked.
Also point noted about github markdown.

Was this page helpful?
0 / 5 - 0 ratings