Re: Use on group_concat Yes Murali, i tried that in lower version. ....
But there is someother way to get the result, this is somewhat similar to MySQL group_concat. It's seems to a big query.. just try this..
-- Create table for manipulation....
CREATE TABLE EMP (ID NUMBER, ENAME VARCHAR2(30), DEPT_ID INTEGER);
INSERT INTO EMP VALUES(1,'Raj', 10);
INSERT INTO EMP VALUES(2,'Kumar', 20);
INSERT INTO EMP VALUES(3,'Selvam', 10);
INSERT INTO EMP VALUES(4,'John', 10);
INSERT INTO EMP VALUES(5,'Smith', 10);
-- Query...
WITH DATA
AS
(
SELECT dept_id, ename, ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY ename) rnum,
COUNT(*) OVER (PARTITION BY dept_id) count FROM emp
)
SELECT dept_id, ltrim(sys_connect_by_path(ename,','),',') Result_String
FROM DATA WHERE rnum = count
start with rnum = 1
CONNECT BY PRIOR dept_id = dept_id and prior rnum = rnum-1
ORDER BY dept_id;
--------------------------------------------------------------------------------
DEPT_ID RESULT_STRING
--------------------------------------------------------------------------------
10 John,Raj,Selvam,Smith
20 Kumar
--------------------------------------------------------------------------------
However, this is not the same result as we get in mysql using the below mysql query.
SELECT group_concat(ename) as Result_String FROM EMP;
Result_String
---------------------------------------
John,Raj,Selvam,Smith,Kumar
__________________ Keep smiling... |