Welcome to OGeek Q&A 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...