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...
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.
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.
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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With