【发布时间】:2022-01-10 08:32:19
【问题描述】:
我正在 Node.js 上创建项目项目并使用 oracledb 模块。我应该调用带有参数的存储过程,但是当我尝试将数字参数传递给过程时,我得到了这个错误:
(节点:6952)UnhandledPromiseRejectionWarning:错误:ORA-06502:PL/SQL:数字或值错误
这是程序:
create or replace procedure delete_song
(s_id in number, procedure_result out boolean) is
begin
delete from PLAYLIST_SONGS where SONG_ID = s_id;
delete from SONG where ID = s_id;
procedure_result:=true;
commit ;
exception when others
then
procedure_result:= false;
rollback;
end;
我在 Node.js 应用程序中执行程序的代码:
router.delete("/:id", async (req, res) => {
const connection = await orcldb.getConnection(dbconf);
let in_id;
if (req.params.id === undefined) {
throw new Error("Bad request");
} else {
in_id = parseInt(req.params.id);
}
console.info("id: ", in_id, typeof in_id);
let procedureResult = await connection.execute(
`
BEGIN
DB_ADMIN.DELETE_SONG(:id, :ret);
END;`,
{
id: in_id,
ret: { dir: orcldb.BIND_OUT, type: orcldb.DB_TYPE_BOOLEAN },
}
);
let result = procedureResult.outBinds.ret;
if (!result) {
throw new Error("Delete song failed");
}
resultSet.close();
res.end("Success");
});
当我从 datagrip 调用此过程时(例如)一切正常,脚本:
declare
result boolean;
begin
DB_ADMIN.DELETE_SONG(41, result);
end;
连接到数据库并获取数据正常工作。 还有我的数据库架构:
Db 用户可以调用存储过程。 我正在使用 Oracle 12c。
我希望有人能帮助我,我很抱歉我的英语不好。
【问题讨论】:
标签: node.js oracle express stored-procedures node-oracledb