我试图获取id在1,2,3的行。
这是我的代码。
app.use('/', async function(req, res, next){
try{
var query = await connection.execute(`SELECT * FROM ERROR_LIST WHERE ID IN :1`, [[1,2,3]]);
console.log(query);
res.send(query.rows)
} catch(err) {
next(err);
}
next();
});
结果是: ORA-01484: 数组只能被绑定到PLSQL语句上
在node-oracledb的文档中,有整整一节是关于 将多个值绑定到一个SQL WHERE IN子句。.
你需要一个解决方案,最简单的是像。
const sql = `SELECT last_name FROM employees WHERE first_name IN (:bv1, :bv2, :bv3, :bv4)`;
const binds = ['Alyssa', 'Christopher', 'Hazel', 'Samuel'];
const result = await connection.execute(sql, binds);