I am working on ORACLE STORED PROCEDURES and I have a doubt. I have a query which fetches more than 1 row and I want to store all those 3 row's values in 1 Variable. Can anybody please help me with this.
My QUERY goes like this :
SELECT STUDENT_NAME
FROM STUDENT.STUDENT_DETAILS
WHERE CLASS_ID= 'C';
Here this query fetches 3 names
Jack, Jill, Bunny
I want all those 3 names to be stored in 1 variable i.e C_NAMES. And after that I am using that variable in further steps of my procedure.
Can anyone please help me with this.
I would highly appreciate your time and effort.
Thanks in advance,
Vrinda :)
You'll need a cursor for that:
Depending on your Oracle version(>= 11G(11.2)), you can use LISTAGG:
EDIT: If your Oracle version is inferior to 11G(11.2), take a look here
Hi all and Thank you for your time. I have resolved the question and all thanks to Ederson.
Here is the solution :
Now if you are using this in a stored procedure or PLSQL you just have to create a variable and use
SELECT INTO
with it and print the variable.Here is the code
Thanks again for your help people.