How do I select from Bulk Collected Table of Records Type

浪尽此生 提交于 2019-12-05 07:24:38

Your problem is actually a PLS-00642 error, rather than ORA-22905. Essentially you can't use local collection types in SQL statements. The solution therefore, is to define your types at the schema level. When defining types in this way, we cannot use the %TYPE syntax, and instead must explicitly define the column (Getting PLS-00201 error while creating a type in oracle) i.e.

create or replace type rec_type as object (
  COLUMN_1 integer,
  COLUMN_2 varchar2(128)
);

create or replace type tab_type as table of rec_type;

You then need to explicitly convert the values into the relevant type in order to perform the bulk collect as mentioned here: ORA-00947 Not enough values while declaring type globally.

Your procedure would therefore look something like this:

PROCEDURE MYPROC((PARAMS))AS
  TABLE_1 TAB_TYPE;
  lCount  integer;
BEGIN

  SELECT  REC_TYPE(COLUMN_A, COLUMN_B)
  BULK COLLECT INTO TABLE_1 
  FROM  TABLE_A;

  SELECT COUNT(*) INTO lCount FROM TABLE(TABLE_1);
END MYPROC;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!