node-oracledb调用Oracle存储过程触发SIGSEGV段错误求助
问题:调用Oracle存储过程触发SIGSEGV段错误
环境信息
- Node.js版本:18.16.1
- oracledb版本:5.5.0
- 部署环境:AWS ECS的AWS Linux 64位Docker镜像
问题描述
已完成Oracle客户端初始化与数据库连接,执行SELECT语句正常,但调用指定存储过程时触发SIGSEGV(段错误),仅返回命令因段错误终止的提示,无其他错误详情。
相关代码
Node.js调用代码
import oracledb from 'oracledb'; try { oracledb.initOracleClient(libDirObj); //success connection = await oracledb.getConnection({ user:xxxx password:xxxx connectString:xxxx });//success let codeC ='3'; await connection.execute(//failed `BEGIN packageName.procedureName(:codeA,:codeB,:codeC,:codeD,:codeE);END;` ,{ codeA : { dir : oracledb.BIND_IN, val: 1111}, codeB : { dir : oracledb.BIND_IN, val: ''}, codeC : { dir : oracledb.BIND_IN, val: codeC}, codeD : { dir : oracledb.BIND_OUT, type : oracledb.STRING}, codeE : { dir : oracledb.BIND_INOUT, val: [20,30] , type: oracledb.NUMBER,maxArraySize: 200 } ,{ function (err, ret) { if (err) { console.log('[ERROR] oracle:',e); //show nothing }else{ console.log('ret:',ret); //show nothing } } } catch (e) { console.log('[ERROR] oracle:',e); //show nothing }
Oracle存储过程定义
CREATE OR REPLACE packageName IS TYPE char_array IS TABLE OF VARCHAR2(10) INDEX BY BINARY_INTEGER; TYPE num_array IS TABLE OF NUMBER INDEX BY BINARY_INTEGER; PROCEDURE procedureName( codeA IN NUMBER, codeB IN VARCHAR2, codeC IN VARCHAR2, codeD OUT VARCHAR2, codeE IN OUT num_array, )
错误信息
error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. ERROR Command was killed with SIGSEGV (Segmentation fault): node ./server/index.mjs at makeError (node_modules/nuxi/dist/shared/nuxi.6b390535.mjs:619:11) at handlePromise (node_modules/nuxi/dist/shared/nuxi.6b390535.mjs:1026:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.invoke (node_modules/nuxi/dist/chunks/preview.mjs:63:5) at async _main (node_modules/nuxi/dist/cli.mjs:50:20)
排查与解决建议
- 关联数组绑定配置错误:存储过程中
codeE是Oracle的关联数组(INDEX BY BINARY_INTEGER),Node.js代码中直接用普通数组绑定会导致类型不匹配,触发段错误。需添加dbType: oracledb.DB_TYPE_PLSQL_ASSOCIATIVE_ARRAY配置:codeE : { dir : oracledb.BIND_INOUT, val: [20,30], type: oracledb.NUMBER, dbType: oracledb.DB_TYPE_PLSQL_ASSOCIATIVE_ARRAY, maxArraySize: 200 } - 回调与await混用:同时使用
await和回调函数会导致错误无法被try/catch捕获,且逻辑混乱。需移除回调,改用纯await写法:const result = await connection.execute( `BEGIN packageName.procedureName(:codeA,:codeB,:codeC,:codeD,:codeE);END;`, { codeA : { dir : oracledb.BIND_IN, val: 1111}, codeB : { dir : oracledb.BIND_IN, val: ''}, codeC : { dir : oracledb.BIND_IN, val: codeC}, codeD : { dir : oracledb.BIND_OUT, type : oracledb.STRING}, codeE : { dir : oracledb.BIND_INOUT, val: [20,30], type: oracledb.NUMBER, dbType: oracledb.DB_TYPE_PLSQL_ASSOCIATIVE_ARRAY, maxArraySize: 200 } } ); console.log('ret:', result); - 修复基础语法错误:原代码中
getConnection的配置参数缺少逗号、try块未闭合,这些问题会导致代码逻辑异常,需先修正。 - 验证Oracle客户端兼容性:确保使用的Oracle Instant Client版本与oracledb 5.5.0兼容(支持12.2到19c/21c版本),版本不匹配可能引发段错误。
内容的提问来源于stack exchange,提问作者teachMepls
相关产品推荐
相关产品推荐

