【问题标题】:"ORA-01036: illegal variable name/number"“ORA-01036: 非法变量名/编号”
【发布时间】:2019-10-28 17:50:01
【问题描述】:

我正在尝试使用 oracledb 客户端从 nodejs 对 oracle 数据库执行查询并获取“ORA-01036:非法变量名称/编号”。我尝试了多种建议的方式来传递我的变量但失败了。查询使用硬编码值。

这是我的示例代码:

`# try 1
 var selectStatement = "SELECT * FROM FILEPROCESS_USER where EMAIL like 
 ?";
 # try 2 
var selectStatement = "SELECT * FROM FILEPROCESS_USER where EMAIL like" + EMAIL+;
# try 3
var bindVars = {
    userid : EMAIL,
    resultSet: {dir: oracledb.BIND_OUT, type: oracledb.STRING, maxSize: 
32767},
    error: {dir: oracledb.BIND_OUT, type: oracledb.STRING, maxSize: 4000} } ;
   connection.execute( "SELECT * FROM FILEPROCESS_USER where EMAIL= 
  :userid", bindVars {*



 handleDatabaseOperation( req, res, function (request, response, 
 connection) 
  {
   var EMAIL = 'ABC@GMAIL.COM';
   connection.execute( selectStatement, [email], 
   outFormat: oracledb.OBJECT 
    },function (err, result) {
        if (err) {
       console.log('Error in execution of select statement'+err.message);
       response.writeHead(500, {'Content-Type': 'application/json'});
       response.end(JSON.stringify({ status: 500, detailed_message: 
       err.message })
       );
       } 
    else {
    response.writeHead (200, {'Content-Type': 'application/json'});
    response.end(JSON.stringify(result.rows));
    }
 `

得到“ORA-01036: 非法变量名/编号”或空白结果

【问题讨论】:

    标签: node.js node-oracledb


    【解决方案1】:

    尝试 #1 无效,因为 Oracle 数据库不使用该语法。

    尝试 #2 没有奏效,原因有两个: "SELECT * FROM FILEPROCESS_USER where EMAIL like" + EMAIL+;

    首先,“like”和“EMAIL”之间没有空格,因此它们被连接在一起。

    其次,它没有正确使用绑定变量。

    这会奏效的:

    "SELECT * FROM FILEPROCESS_USER where EMAIL like :EMAIL";

    尝试 #3 不起作用,因为您在 SQL 中有一个绑定变量,但您提供了多个绑定变量值。

    【讨论】:

    • 只是跟进......如果你还没有看过这个系列,你可能会发现它很有用:jsao.io/2018/03/…
    • 好吧,让我试着确认一下
    猜你喜欢
    • 2013-01-06
    • 2018-05-21
    • 2011-10-05
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 2016-04-03
    • 1970-01-01
    • 2018-10-16
    相关资源
    最近更新 更多