0

I have following code but it just doesn't seem to work. I don't understand what's wrong.

await connection.execute(
`UPDATE mytable SET WEIGHT = :WEIGHT
 WHERE ITEM_ID = :ITEM_ID AND NAME = :NAME`
 ), Bindings[0],{autoCommit: true, outFormat : oracledb.OBJECT};

Where Bindings[0] is:

{
   ITEM_ID: 'dfghjkl',
   WEIGHT: '10',
   NAME: 'test'
}

This yields the following error: Error: ORA-01008: not all variables bound

Please help

1
  • Show us a real, runnable script and also the SQL to create mytable. I tried to guess what you did and my script ran fine. Commented Jul 2, 2019 at 12:46

1 Answer 1

2

This works for me:

'use strict';

process.env.ORA_SDTZ = 'UTC';

const oracledb = require('oracledb');
let config = require('./dbconfig.js');

async function run() {
  let connection;

  try {
    connection = await oracledb.getConnection(config);

    let result;

    try {
      result = await connection.execute(`drop table mytable`);
    } catch (e) {
      if (e.errorNum != 942) console.error(e);
    }

    await connection.execute(`create table mytable (weight number, item_id varchar2(20), name varchar2(30))`);

    await connection.execute(`insert into mytable (weight, item_id, name) values (0, 'dfghjkl', 'test')`);    

    let Bindings = [];
    Bindings[0] = {
      ITEM_ID: 'dfghjkl',
      WEIGHT: '10',
      NAME: 'test'
    };

    result = await connection.execute(
      `UPDATE mytable SET WEIGHT = :WEIGHT WHERE ITEM_ID = :ITEM_ID AND NAME = :NAME`,
      Bindings[0], {autoCommit: true, outFormat : oracledb.OBJECT});

    result = await connection.execute(`select * from mytable`);
    console.log(result.rows);
  } catch (err) {
    console.error(err);
  } finally {
    if (connection) {
      try {
    await connection.close();
      } catch (err) {
    console.error(err);
      }
    }
  }
}

run();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.