执行存储过程时,node-oracledb错误

时间:2018-11-26 12:14:54

标签: node.js oracledb node-oracledb

我正在使用Node 10.x和Oracledb 3.0

我正在尝试在node.js中执行存储过程

我在过程中有异常块,如下所示:

EXCEPTION
WHEN NO_DATA_FOUND THEN
OUT_STATUS:='FAILURE';
OUT_STATUS_DESC:='USER NOT MAPPED TO A GROUP';
WHEN OTHERS THEN
OUT_STATUS:='FAILURE';
OUT_STATUS_DESC:=dbms_utility.format_error_backtrace;

每当控件转到Exception块,并使其低于node.js中的错误时。

  

错误:ORA-24338:语句句柄未执行

但是,如果我用相同的IN参数在db中执行过程,则它会给出错误的正确OUT参数,并且CURSOR关闭。

这些是过程中的OUT参数类型。

OUT_STATUS OUT VARCHAR2, OUT_STATUS_DESC OUT VARCHAR2, OUT_MENU_NAME OUT SYS_REFCURSOR

可能是什么问题?

2 个答案:

答案 0 :(得分:0)

即使您不打算在node-oracledb代码中使用它们,也必须将所有OUT变量设置为某种值,请参见https://github.com/oracle/node-oracledb/issues/886

事实证明,在基于Oracle C'OCI'API的所有Oracle DB驱动程序(例如,node-oracledb)中都是如此,但症状问题更常见于node-oracledb。

答案 1 :(得分:0)

解决方法是,如果之前没有打开过,则在异常块中打开 OUT_MENU_NAME 游标为零行:

EXCEPTION
  WHEN NO_DATA_FOUND THEN
    OUT_STATUS:='FAILURE';
    OUT_STATUS_DESC:='USER NOT MAPPED TO A GROUP';

    -- Replicate your normal cursor output and filter on something that will never be true:
    OPEN  OUT_MENU_NAME FOR
      SELECT 'Nothing'         AS col1,
             DATE '1970-01-01' AS col2,
             0                 AS col3
      FROM DUAL
      WHERE 1 = 0;

  WHEN OTHERS THEN
    OUT_STATUS:='FAILURE';
    OUT_STATUS_DESC:=dbms_utility.format_error_backtrace;

    -- Replicate your normal cursor output and filter on something that will never be true:
    OPEN  OUT_MENU_NAME FOR
      SELECT 'Nothing'         AS col1,
             DATE '1970-01-01' AS col2,
             0                 AS col3
      FROM DUAL
      WHERE 1 = 0;