Swaminathan K
asked on
Unable to store the column values in a collection using select statement in oracle
Hi Team,
Below is the code, I have written to store the column values into a collection using a select statement. I am getting the below error, kindly help me in this regard. Any help is really appreciated.
CREATE TYPE enames_var IS VARRAY(200) OF VARCHAR2(30);
declare
l_empdata enames_var;
begin
select first_name into l_empdata
from employees;
end;
/
Error:
ORA-06550: line 4, column 8:
PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got CHAR
ORA-06550: line 4, column 1:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Below is the code, I have written to store the column values into a collection using a select statement. I am getting the below error, kindly help me in this regard. Any help is really appreciated.
CREATE TYPE enames_var IS VARRAY(200) OF VARCHAR2(30);
declare
l_empdata enames_var;
begin
select first_name into l_empdata
from employees;
end;
/
Error:
ORA-06550: line 4, column 8:
PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got CHAR
ORA-06550: line 4, column 1:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
to read multiple values into a collection - yes you must use bulk collect.
if you want to read one value at a time (which is less efficient, so you probably shouldn't do that) you can do a normal select value into variable, but then you won't be using the collection, you'll be using a scalar variable.
I suppose you "could" (again, possible, but probably not a good idea) manually iterate through a collection and select into
l_empdata(1) then l_empdata(2), then l_empdata(3) and so on.
if you want to read one value at a time (which is less efficient, so you probably shouldn't do that) you can do a normal select value into variable, but then you won't be using the collection, you'll be using a scalar variable.
I suppose you "could" (again, possible, but probably not a good idea) manually iterate through a collection and select into
l_empdata(1) then l_empdata(2), then l_empdata(3) and so on.
ASKER
is it necessary to use bulk collect , can;t we store it without using it?