oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.25k stars 1.07k forks source link

DML RETURNING INTO out binds not always an array? #1495

Closed mdecurtins closed 2 years ago

mdecurtins commented 2 years ago

Hi,

It looks like DML statements (affecting a single row only) with RETURNING INTO clauses with out binds do not always return a single-element array when the statement is wrapped in an anonymous PL/SQL block (BEGIN ... END;). The API docs section on DML RETURNING bin parameters indicates that "each DML RETURNING bind OUT parameter is returned as an array containing zero or more elements."

That is, the outBinds are single-element arrays, as expected, with the following SQL:

INSERT INTO MyTable ( FOO, BAR, BAZ )
VALUES ( :foo, :bar, :baz )
RETURNING FOO, BAR, BAZ
INTO :outFoo, :outBar, :outBaz

The outBinds are not arrays, however, when this DML statement is wrapped in a PL/SQL block:

BEGIN
  INSERT INTO MyTable ( FOO, BAR, BAZ )
  VALUES ( :foo, :bar, :baz )
  RETURNING FOO, BAR, BAZ
  INTO :outFoo, :outBar, :outBaz;
END;

I'm aware we're running an older version of node-oracledb, but I can't tell whether RETURNING INTO bind behavior has changed between 4.2 and the current stable version 5.3 (it doesn't appear to have changed, that I can tell).

Just looking to confirm if this is intended behavior. Thanks!

Versions: Oracle DB version: 19c NodeJS version 12.22.12 Ubuntu 20.04 linux/x86_64 node-oracledb 4.2.0 Oracle Instant Client 12.2.0.1

anthony-tuininga commented 2 years ago

This is indeed expected behavior. The first statement is a DML returning statement and the documentation on DML returning statements applies. The second statement is a PL/SQL statement. The fact that you have a DML returning statement embedded in it is not relevant. :-)

mdecurtins commented 2 years ago

Of course, makes sense. Thanks for the clarification!