我尝试在 SELECT 语句中使用表类型的变量,但它发生错误:
DECLARE
TYPE v2t IS TABLE OF table_a.id%TYPE INDEX BY BINARY_INTEGER;
TYPE test_type IS TABLE OF table_a.id%TYPE INDEX BY BINARY_INTEGER;
test_table1 test_type;
test_table2 test_type;
databaseArray v2t;
BEGIN
SELECT id BULK COLLECT INTO test_table1 FROM
(SELECT id FROM test_a WHERE some_flag = 1);
FOR i IN 1..test_table1.COUNT LOOP
databaseArray(i) := test_table1(i);
END LOOP;
SELECT id BULK COLLECT INTO test_table2 FROM
(SELECT id FROM TABLE(databaseArray)); --error ORA-22905
END;
test_table1 在表格中不可见。 有没有办法在SELECT语句中使用 test_table1 ? 我需要有两个结果子集。
答案 0 :(得分:2)
如果您不想在架构级别声明自己的类型,可以使用built-in table type,只要有一个与您的基础数据类型匹配且您没有太多的值放进去:
DECLARE
TYPE test_type IS TABLE OF user_objects.object_id%TYPE
INDEX BY BINARY_INTEGER;
test_table1 test_type;
test_table2 test_type;
databaseArray sys.odcinumberlist;
BEGIN
SELECT object_id
BULK COLLECT INTO test_table1
FROM user_objects;
databaseArray := sys.odcinumberlist();
FOR i IN 1..test_table1.COUNT LOOP
databaseArray.extend;
databaseArray(i) := test_table1(i);
END LOOP;
SELECT column_value
BULK COLLECT INTO test_table2
FROM TABLE(databaseArray);
END;
/
anonymous block completed