我创建了类型
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 错误。有什么问题吗?
问题是错误所说的,当它需要用户定义的类型时,您正在将数字传递给集合。那是因为您的查询返回一个数字,而不是一个对象。所以代替:
select product_id bulk collect into int_array from product;
做:
select rec_int_g(product_id) bulk collect into int_array from product;