无法在 Node.js node-oracledb 模块中绑定
Unable to bind in Node.js node-oracledb module
我有以下代码,但它似乎不起作用。我不明白怎么了。
await connection.execute(
`UPDATE mytable SET WEIGHT = :WEIGHT
WHERE ITEM_ID = :ITEM_ID AND NAME = :NAME`
), Bindings[0],{autoCommit: true, outFormat : oracledb.OBJECT};
其中 Bindings[0] 是:
{
ITEM_ID: 'dfghjkl',
WEIGHT: '10',
NAME: 'test'
}
这会产生以下错误:
错误:ORA-01008:并非所有变量都绑定
请帮忙
这对我有用:
'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();
我有以下代码,但它似乎不起作用。我不明白怎么了。
await connection.execute(
`UPDATE mytable SET WEIGHT = :WEIGHT
WHERE ITEM_ID = :ITEM_ID AND NAME = :NAME`
), Bindings[0],{autoCommit: true, outFormat : oracledb.OBJECT};
其中 Bindings[0] 是:
{
ITEM_ID: 'dfghjkl',
WEIGHT: '10',
NAME: 'test'
}
这会产生以下错误: 错误:ORA-01008:并非所有变量都绑定
请帮忙
这对我有用:
'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();