ORA-00947 Not enough values while declaring type globally

24.9k views Asked by At
 create table foo(
   id number,
   status varchar2(10)
 );

Table created.

insert into foo values( 1, 'open' );
insert into foo values( 2, 'close' );
insert into foo values( 3, 'open' );
insert into foo values( 4, 'open' );
insert into foo values( 5, 'close' );

create type foo_obj is object (
      id number,
      status varchar2(10)
    );
   /

 create type foo_nt
     as table of foo_obj;
  /

 create or replace package test_bulk
 is 

 procedure temp;

 end;
 /

 create or replace package body test_bulk
 is 

 procedure  temp
   is 
   v_nt  foo_nt;
   begin
     select id ,status 
     bulk collect into v_nt
     from foo;

   end temp;

   end test_bulk;

This is a very odd situation, when I create a type object and nested table of that type Globally and create a variable of the nested table type and bulk collect into that variable I get

ORA-00947: not enough values error

However, when I declare a record type and nested table of that record type And then a variable of the nested table Inside the package , then the above bulk collect works and it will not throw error

Can anyone help me out with this?

1

There are 1 answers

1
Bob Jarvis - Слава Україні On BEST ANSWER

You can't just put values into a table of objects - you need to convert the values into objects of the appropriate type and then insert the objects. Try

procedure temp is
  v_nt  foo_nt;
begin
  select FOO_OBJ(id ,status)
    bulk collect into v_nt
    from foo;
end temp;

Not tested on animals - you'll be first!

Share and enjoy.