如何在Oracle PL / SQL中选择INTO数组?

时间:2014-06-30 11:00:22

标签: sql oracle plsql

我正在尝试在数组中保存一组ID:

declare
 cities_ids array_of_numbers;
begin
select id into cities_ids from objects where id = 1115464;
    FOR i IN 1..cities_ids.COUNT LOOP
        DBMS_OUTPUT.PUT_LINE(cities_ids(i));
    END LOOP;
end;

执行后,我收到了下一个错误:

ORA-00932: inconsistent datatypes. Expected UDT, got NUMBER.

请解释我做错了什么......

1 个答案:

答案 0 :(得分:26)

非常简单:BULK COLLECT缺失。

declare
 cities_ids arrayofnumbers;
begin
select object_id BULK COLLECT into cities_ids from nc_objects where object_id = 1000;
    FOR i IN 1..cities_ids.COUNT LOOP
        DBMS_OUTPUT.PUT_LINE(cities_ids(i));
    END LOOP;
end;