Skip to Main Content
  • Questions
  • Error Message:ORA-22905: cannot access rows from a non-nested table item

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Shivani.

Asked: December 05, 2015 - 4:14 am UTC

Last updated: December 09, 2015 - 9:06 am UTC

Version: Oracle 11.2

Viewed 10K+ times! This question is

You Asked

Hello Tom,

Please help me I need to get collection records in cursor so that it can be return as a out parameters but I am getting following errors:

Error(30,6): PL/SQL: SQL Statement ignored
Error(30,20): PL/SQL: ORA-22905: cannot access rows from a non-nested table item
Error(30,26): PLS-00642: local collection types not allowed in SQL statements

Also below is my procedure:

create or replace procedure POC_PROC (cv_1 OUT SYS_REFCURSOR)as

type tt_SearchMatch_object is record(
ID number,
TRADEID number,
source number,
productID number ,
swapIndicator number,
UPDATEINDICATOR number
);

type tt_SearchMatch_nst is table of tt_SearchMatch_object ;
v_tt_SearchMatch_nst tt_SearchMatch_nst := tt_SearchMatch_nst();

begin
DBMS_OUTPUT.PUT_LINE(to_char(systimestamp,'HH24:MI:SS:FF3')||' Start ');

execute immediate 'create table abc(vid number , v_tt_SearchMatch_nst tt_SearchMatch_nst)
nested table v_tt_SearchMatch_nst store as v_tt_SearchMatch_nst_nt';

select th.id,
th.tRADEID,
th.source,
th.productID,
th.swapindicator,
th.UPDATEINDICATOR bulk collect into v_tt_SearchMatch_nst
from Tradeheader th;

open cv_1 for
select * from table(v_tt_SearchMatch_nst); --Giving errors:Error(30,6): PL/SQL: SQL Statement ignored
--Error(30,20): PL/SQL: ORA-22905: cannot access rows from a non-nested table item
--Error(30,26): PLS-00642: local collection types not allowed in SQL statements

--update table ( select c.v_tt_SearchMatch_nst from abc c) t
-- set t.id = 5;



DBMS_OUTPUT.PUT_LINE(to_char(systimestamp,'HH24:MI:SS:FF3')||' Finish ');

end;


and Connor said...

You need to declare your types explicitly as database objects, not as components in a procedure, ie

create or replace type tt_SearchMatch_object is object
(
...
);

create or replace type tt_SearchMatch_nst is table of tt_SearchMatch_object ;

So that they are database objects in their own right.

Hope this helps.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

anurag bishnoi, December 08, 2015 - 6:50 pm UTC

Hi,

In this procedure you are using EXE.. IMM.. to run a DDL and creating a table abc and using the same table below in another statement.

Tom, Is it possible to use the table because in my practical if i am using the table created by exec.. imm.. my procedure is throwing an error.

Here is my code

set serveroutput on
clear screen

drop table abc;
/

drop type typ_obj;
/

drop type my_obj;
/

create or replace type my_obj is object(
x number,
y varchar2(20));
/

create or replace type typ_obj is table of my_obj;
/

create or replace procedure p_nest_tab as
v_type_obj typ_obj := typ_obj();
cnt number;
begin
execute immediate 'create table abc(vid number,x typ_obj)
nested table x store as v_type_obj_tab';
--select count(1) into cnt from abc;
end;
/

begin
p_nest_tab;
end;
/

this time it will make table abc
BUT if you uncomment the code '--select count(1) into cnt from abc;'

it works.

Kindly explain.
Chris Saxon
December 09, 2015 - 9:06 am UTC

At the time your procedure was compiled the table 'abc' did not exist.

As a general rule, we dont want to be createing tables on the fly in Oracle - that not a good way of building applications.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library