Avatar of Swaminathan K
Swaminathan KFlag for India

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:


* Oracle PL/SQLOracle Database

Avatar of undefined
Last Comment
Sean Stuber
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Swaminathan K
Swaminathan K
Flag of India image

ASKER

Hi Stuber
is it necessary to use bulk collect , can;t we store it without using it?
Avatar of Sean Stuber
Sean Stuber

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.



Oracle Database
Oracle Database

Oracle is an object-relational database management system. It supports a large number of languages and application development frameworks. Its primary languages are SQL, PL/SQL and Java, but it also includes support for C and C++. Oracle also has its own enterprise modules and application server software.

81K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo