Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to SELECT INTO array of Numbers in Oracle PL/SQL?

Tags:

I'm trying to save set of ids in array:

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; 

After execution, I got next error:

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

Please explain what I did wrong...

like image 734
Boris Mitioglov Avatar asked Jun 30 '14 11:06

Boris Mitioglov


People also ask

Can we use SELECT into in PL SQL?

You can make the use of the SELECT INTO statement in PL/ SQL to retrieve the row containing single or multiple column values in the resultant for storing them in variables.

How do I write multiple SELECT statements in Oracle?

For multiple SELECTs you can have multiple SELECT INTO clause, each clause would store the result of respective SQL. To return multiple rows, you could use CURSOR . In your case, with multiple statements, you can have two REFCURSOR . Show activity on this post.

How do I assign multiple values to a variable in PL SQL?

Procedure Starting odcivarchar2list('0001','0002','0003')) into v_acct5 --- Storing the value returned by the function from dual; for i in cur_Var(v_acct5) -- Passing the resultset(array list) from the function to the Cursor. loop dbms_output.

What is array in PL SQL?

A PL/SQL associative array is a collection type that associates a unique key with a value. An associative array has the following characteristics: An associative array type must be defined before array variables of that array type can be declared. Data manipulation occurs in the array variable.


1 Answers

Very simple: BULK COLLECT is missing.

declare  cities_ids array_of_numbers; begin select id BULK COLLECT 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; 
like image 200
Erich Kitzmueller Avatar answered Sep 20 '22 13:09

Erich Kitzmueller