【问题标题】:nodejs oracledb select data WHERE IN values arraynodejs oracledb 选择数据 WHERE IN 值数组
【发布时间】:2020-08-15 13:40:34
【问题描述】:

我正在尝试获取 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:数组只能绑定到 PL/SQL 语句

【问题讨论】:

    标签: node.js arrays where-in node-oracledb


    【解决方案1】:

    node-oracledb 文档有一整节 Binding Multiple Values to a SQL WHERE IN Clause

    您需要一种解决方案,其中最简单的是:

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-16
      • 2014-11-12
      • 2010-09-15
      • 2016-12-04
      • 2016-02-03
      • 1970-01-01
      • 2017-05-24
      • 1970-01-01
      相关资源
      最近更新 更多