How can I set multiple into
inside a select query in Oracle according to the following sql query.
declare
v_a out varchar2;
v_b out varchar2;
v_c out varchar2;
begin
select a , b , c into v_a, v_b, v_c from table
end
How can I set multiple into
inside a select query in Oracle according to the following sql query.
declare
v_a out varchar2;
v_b out varchar2;
v_c out varchar2;
begin
select a , b , c into v_a, v_b, v_c from table
end
If your table contains single record then what you have given is correct, except the things mentioned by @AlexPoole in his comments. Also, you cannot use OUT
in the annonymous block.
In case your table contains multiple records then you will need to create a collection to store records and do BULK COLLECT
in your query. the pseudo code for that will be something like:
Declare
TYPE c_var is table of varchar2(100);
v_a c_var ;
v_b c_var ;
v_c c_var ;
Begin
Select a, b, ,c BULK COLLECT INTO v_a, v_b, v_c from table;
END;
You can then loop through the collection to access the individual elements.
Hope it Helps
Vishad