0

I've created a VARRAY type:

CREATE TYPE my_array AS varray(1024) OF VARCHAR2(512);

I know I can create an instance of my_array from a list of values using my_array():

SELECT my_array('foo', 'bar');

But is there a way to create an instance from the results of a query? I'm thinking something like this:

SELECT my_array(SELECT table_name FROM all_tables WHERE owner = 'SCOTT')
  FROM dual;

Or, failing that, an aggregate that returns a my_array:

SELECT my_array_agg(table_name) FROM all_tables WHERE owner = 'SCOTT';

Is this do-able in Oracle?

4

1 回答 1

2

在plsql中批量收集

declare 
arr my_array;
begin 
SELECT table_name bulk collect into arr FROM all_tables WHERE owner = 'SCOTT';
end;

或者

select collect(table_name) from all_tables where owner = 'SCOTT';

但是你不能在 sqlplus 中对这样的集合做任何事情。

于 2013-05-01T06:31:40.340 回答