如何解决如何在 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),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_name: data.object_name}
}
以上是我用过的。我期待第一个 catch 块中出现错误,如下图所示
解决方法
您的问题没有显示在 node-oracledb 中执行的语句文本,但 SQL Dev 屏幕截图似乎显示您正在创建或编译存储过程。
在 node-oracledb 中创建 PL/SQL 过程和函数时,当前版本 5.1 不支持 PL/SQL 编译错误返回的“success with info”错误。这在增强请求 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
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。