简体   繁体   English

Node.Js Oracledb 可选数组作为 IN 绑定参数到 Oracle 过程

[英]Node.Js Oracledb optional Array as IN bind parameter to Oracle Procedure

I am trying to pass array in procedure as mentioned in following link but that array should be optional.我正在尝试按照以下链接中的说明在过程中传递数组,但该数组应该是可选的。 I am doing bulk insert using forall in the procedure.我正在程序中使用 forall 进行批量插入。 but some time list can be empty as well and still other stuff in the procedure should be executed succesfully.但是某些时间列表也可以为空,并且程序中的其他内容应该成功执行。

https://github.com/oracle/node-oracledb/blob/master/doc/api.md#plsqlindexbybinds https://github.com/oracle/node-oracledb/blob/master/doc/api.md#plsqlindexbybinds

connection.execute(
  "BEGIN mypkg.myinproc(:id, :vals); END;",
  [
    1234,
    { type: oracledb.NUMBER,
       dir: oracledb.BIND_IN,
       val: [1, 2, 23, 4, 10]
    }
  ],

  function (err) { . . . });

works find but if i don't want to pass vals i am getting errors可以找到,但如果我不想通过 vals,我就会收到错误

i tried我试过了

val:[]
val: null
val: undefined

and not having val at all

i am getting following error messages我收到以下错误消息

when trying to pass null or undefined or do not pass:尝试传递 null 或 undefined 或不传递时:

PLS-00306: wrong number or types of arguments in call to 'INSERT_PROCEDURE'

When trying to pass empty array尝试传递空数组时

NJS-039: empty array is not allowed for IN bind

I did a work around by passing array with null我通过使用 null 传递数组来解决问题

 val:[null]

and in procedure removing nulls from the list before executing FORALL.并在执行 FORALL 之前从列表中删除空值。

this works for temporary but i would really like to solve this problem in proper way.这暂时有效,但我真的很想以适当的方式解决这个问题。

I'm going to treat this as a bug (or design flaw) and get someone to look at it.我会将其视为错误(或设计缺陷)并请人查看。 Both PHP OCI8 2.0 and Node node-oracledb 1.11 disallow binding empty arrays, but Python cx_Oracle doesn't. PHP OCI8 2.0 和 Node node-oracledb 1.11 都不允许绑定空数组,但 Python cx_Oracle 不允许。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM