如何在 node-oracledb 5.1 中执行存储过程时出现编译错误

How to get compilation errors while executing stored procedure in node-oracledb 5.1

我正在尝试执行原始存储过程,它在 SQL Developer 中显示了一些编译错误。但它没有在 execute() 方法的回调函数中返回。

ex.runQuery  = async (data)=>{
  //{ "STATUS": "SUCCESS", data: { result }, object_key_seq: data[i].object_key_seq, type: data[i].type, i: i }
  //{ "STATUS": "ERROR", "ERROR": utils.parseError(err, query), object_key_seq: data[i].object_key_seq, type: data[i].type, i: i }
  let connection = null;
  let resutl = null;

  try{
    connection = await oraconnect.getPoolConnection()
    if(data.object_type == 'SEQUENCE' || data.object_type == 'TABLE' || data.object_type == 'VIEW' || data.object_type == 'INDEX'){
      data.script = data.script.slice(0, -1);
    }
    if(data.script.slice(-1) == '/'){
      data.script = data.script.slice(0, -1);
    }
    resutl = await oraconnect.query(connection, data.script, [], 100);
  }catch(err){
    console.log(err);
    return { "STATUS": "ERROR", "ERROR": {errorMessage:err.message}, object_key_seq: data.object_key_seq, type: data.type, object_name :data.object_name}

  }finally{
    if (connection) {

      try {
        await   oraconnect.doRelease(connection);
        //await connection.close();
      } catch (err) {
        console.error(err);
      }
    }
  }

  return { "STATUS": "SUCCESS", data: { resutl }, object_key_seq: data.object_key_seq, type: data.type, object_name: data.object_name}
}

上面是我用的。我预计第一个 catch 块会出现错误,如下图所示

你的问题没有显示在 node-oracledb 中执行的语句文本,但 SQL Dev 屏幕截图似乎显示你正在创建或编译存储过程。

在 node-oracledb 中创建 PL/SQL 过程和函数时,当前版本 5.1 不支持 'success with info' 错误 PL/SQL 编译错误 return。这在增强请求 https://github.com/oracle/node-oracledb/issues/823.

中有说明

您可以通过查询 user_errors 来手动检查问题,例如:

    await connection.execute(
      `create or replace procedure badproc() as
       begin
           INVALID
       end;`);
    const r = await connection.execute(
      `select line, position, text
       from user_errors
       where name = 'BADPROC' and type = 'PROCEDURE'
       order by name, type, line, position`,
      [], { outFormat: oracledb.OUT_FORMAT_OBJECT }
    );
    if (r.rows.length) {
      console.error(r.rows[0].TEXT);
      console.error('at line ', r.rows[0].LINE, 'position', r.rows[0].POSITION);
    }

输出如下:

PLS-00103: Encountered the symbol ")" when expecting one of the following:

   <an identifier> <a double-quoted delimited-identifier>
   current delete exists prior

at line  1 position 19

尝试调用这样一个无效的过程会出现预期的错误:

    const r2 = await connection.execute(`begin badproc(1); end;`);
    console.log(r2);

给出:

[Error: ORA-06550: line 1, column 7:
PLS-00905: object CJ.BADPROC is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored] {
  errorNum: 6550,
  offset: 6
}