批量收集 PL/SQL:ORA-00932:数据类型不一致:预期 UDT 为 NUMBER

问题描述 投票:0回答:1

我创建了类型

create or replace type rec_int_g as object( i integer);
create or replace type typ_int_g is table of rec_int_g;

还有一个函数

create function table_randset 
 return pls_integer is
  
 int_array typ_int_g := typ_int_g();


begin
  
select product_id bulk collect into int_array

  from product;

return randset(int_array);
end; 

但是进入了选择 PL/SQL: ORA-00932: 数据类型不一致: 预期 UDT 为 NUMBER 错误。有什么问题吗?

arrays oracle collections numbers ora-00932
1个回答
0
投票

问题是错误所说的,当它需要用户定义的类型时,您正在将数字传递给集合。那是因为您的查询返回一个数字,而不是一个对象。所以代替:

select product_id bulk collect into int_array from product;

做:

select rec_int_g(product_id) bulk collect into int_array from product;
© www.soinside.com 2019 - 2024. All rights reserved.