ORA-00947 "not enough values" when UPDATE returning BULK COLLECT INTO user created TYPE TABLE

Viewed 135

I am getting the following error when trying to bulk collect into a table type: ORA-00947 "not enough values"

I needed to create a database-level type to access the result set (open cursor) using my application.

file: FOO_STATUS.sql

CREATE OR REPLACE TYPE "FOO_STATUS" AS OBJECT
(
   a NUMBER,
   b NUMBER,
   c NUMBER
);
/

file: FOO_STATUS_TABLE.sql

CREATE OR REPLACE TYPE FOO_STATUS_TABLE IS TABLE OF FOO_STATUS;
/

PACKAGE:

PROCEDURE foo
(
  ...
)
IS
  l_foo FOO_STATUS_TABLE := FOO_STATUS_TABLE();
BEGIN
      UPDATE foo_table
      SET ...
      WHERE ...
      RETURNING foo_table_a, foo_table_b, c BULK COLLECT INTO l_foo; -- ERROR: ORA-00947

OPEN p_results FOR
    SELECT
      foo_results.a   AS a,
      foo_results.b   AS b,
      foo_results.c   AS c,
      other.d         AS d
    FROM
      TABLE( l_foo ) foo_results INNER JOIN other_table other ON foo_results.obj = other.obj
END;
1 Answers

Since l_foo is a table of objects you need to collect objects into this collection instead of just values like

returning foo_status(a, b, c) bulk collect into l_foo

fiddle example

Related