2014-06-30 73 views
10

我試圖在數組保存集ID:如何在Oracle PL/SQL中選擇INTO數組數組?

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. 

請解釋一下我做錯了什麼......

+0

看[這裏](http://www.experts-exchange.com/Database/Oracle/Q_26235824.html)也許這會幫助你。 – Jens

回答

18

非常簡單:缺少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; 
+0

Thanx,男人!它有助於! –