Home » SQL & PL/SQL » SQL & PL/SQL » Retrieving Multiple Rows of Single Column as a String concatenated with comma
Retrieving Multiple Rows of Single Column as a String concatenated with comma [message #36435] Tue, 27 November 2001 21:03 Go to next message
Malli
Messages: 10
Registered: November 2001
Junior Member
I have a table with single column 1000 Rows with Varchar datatype.
I need to get all these separated by a Comma in a single row. Does anybody know how to achieve that?
pl help me
Advance Thanks
Malli

----------------------------------------------------------------------
Re: Retrieving Multiple Rows of Single Column as a String concatenated with comma [message #36437 is a reply to message #36435] Tue, 27 November 2001 22:13 Go to previous message
Rob Baillie
Messages: 33
Registered: November 2001
Member
Well, here's a starting point for you...

DECLARE
--
lc_return_string VARCHAR2(2000);
--
CURSOR cur_string IS
SELECT some_string
FROM some_table
ORDER BY some_field;
--
BEGIN
--
DBMS_OUTPUT.ENABLE;
--
FOR string_rec IN cur_string LOOP
IF lc_return_string IS NOT NULL THEN
lc_return_string := lc_return_string || ',' || string_rec.some_string;
ELSE
lc_return_string := string_rec.some_string;
END IF;
END LOOP;
--
DBMS_OUTPUT.PUT_LINE( lc_return_string );
--
END;
/

Though if anyone knows how to do it in a single select statement I'd be VERY VERY impressed...

----------------------------------------------------------------------
Previous Topic: Re: use variable in SQL statement
Next Topic: sparse vs. dense indexes
Goto Forum:
  


Current Time: Mon Mar 30 00:03:18 CDT 2020