如何将 NodeJS 变量输入到 Oracle SQL 查询中



我正在尝试将nodejs变量传递给sql查询下面是我的代码:

var b= 101;
connection = await oracledb.getConnection(  {
user          : dbConfig.user,
password      : dbConfig.password,
connectString : dbConfig.connectString
});
sql = 'SELECT * FROM mytab where id= b';
binds = {};
                        options = {
                        outFormat: oracledb.OBJECT   // query result format
                        };
                        result = await connection.execute(sql, binds, options);

尝试如下内容:

sql = 'SELECT * FROM mytab where id= $1::int';
options = {
    outFormat: oracledb.OBJECT   // query result format
};
result = await connection.execute(sql, [ b ], options);

最新更新