Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

oracle - ORA-00947 Not enough values while declaring type globally

 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...