Skip to Main Content
  • Questions
  • inconsistent behavior of table() function

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Alexander.

Asked: July 07, 2017 - 2:35 pm UTC

Last updated: August 01, 2018 - 12:36 pm UTC

Version: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Viewed 1000+ times

You Asked

Hi,
I try to use table() function over collection of rows. It fails in delete statements (delete MY_TABLE where xxx in (select yyy from table(collection)). When I use the same construction in select statement it works fine. Same issue exists for update statements. It looks like a obvious Oracle bug.
My test case -

create table Z_TEST (
id integer,
val varchar2(10)
);

create or replace package ZPKG1 as
type ZTestColl is table of Z_TEST%rowtype;
procedure test;
end;
/

create or replace package body ZPKG1 as
tab1 ZTestColl := ZTestColl();

procedure test as
c integer;
begin
dbms_output.put_line('testing select from table()');
select count(*) into c from table(tab1);
dbms_output.put_line('testing select from .. where id in (select id from table())');
select count(*) into c from Z_TEST where id in (select id from table(tab1));
dbms_output.put_line('testing delete from .. where id in (select id from table())');
delete from Z_TEST where id in (select id from table(tab1));
exception when others then
dbms_output.put_line(sqlerrm);
end;
end;
/

exec zpkg1.test;

Output is
testing SELECT from table()
testing SELECT from .. where id in (select id from table())
testing DELETE from .. where id in (select id from table())
ORA-00902: invalid datatype



with LiveSQL Test Case:

and Connor said...

I agree - looks like a bug.

I reproduced in 12.1 and 12.2 on my system.

Please file a bug with Support. (It has more weight if it comes from customer instead of me)

Rating

  (2 ratings)

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

Comments

So... What's the Work-Around?

A reader, June 07, 2018 - 6:20 pm UTC

It's nice to know that I'm not going crazy when I ran into this myself, but it'd be nice to see a working word-around in the meantime.
Connor McDonald
June 08, 2018 - 7:05 am UTC

<code>
SQL> create table Z_TEST (
2 id integer,
3 val varchar2(10)
4 );

Table created.

SQL>
SQL> create or replace package ZPKG1 as
2 type ZTestColl is table of Z_TEST%rowtype;
3 procedure test;
4 end;
5 /

Package created.

SQL>
SQL> create or replace package body ZPKG1 as
2 tab1 ZTestColl := ZTestColl();
3
4 procedure test as
5 c integer;
6 wrapper sys.odcinumberlist;
7 begin
8 dbms_output.put_line('testing select from table()');
9 select count(*) into c from table(tab1);
10 dbms_output.put_line('testing select from .. where id in (select id from table())');
11 select count(*) into c from Z_TEST where id in (select id from table(tab1));
12 dbms_output.put_line('testing delete from .. where id in (select id from table())');
13 select id bulk collect into wrapper from table(tab1) ;
14 delete from Z_TEST where id in ( select column_value from table(wrapper));
15 end;
16 end;
17 /

Package body created.

SQL> sho err
No errors.
SQL>
SQL> set serverout on
SQL> exec zpkg1.test;
testing select from table()
testing select from .. where id in (select id from table())
testing delete from .. where id in (select id from table())

PL/SQL procedure successfully completed.
<code>

Not Just DELETE

D, July 31, 2018 - 2:00 pm UTC

Connor McDonald
August 01, 2018 - 12:36 pm UTC

thanks for the addenda

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