0

I have to concatenate below data

a b c  
1 Text 22-03-2015
1 Text1 22-03-2015
2 Text2 24-05-2015
3 Text5 29-05-2015
1 Text11 23-03-2015

And the expected Output is

a b c
1 Text,text1 22-03-2015
1 Text11 23-03-2016
2 Text2 24-05-2015
3 Text5 29-05-2015

Tried wm_concat function and it works but i cant remove the duplicates from the data and usage of LISTAGG results in error

"ora-01489 result of string concatenation is too long in oracle"

error as columns b contains values greater than 4000 characters.
Any alternatives apart form these 2 functions?

hemalp108
  • 1,209
  • 1
  • 15
  • 23
Annie Jeba
  • 373
  • 1
  • 3
  • 15
  • 1
    One option would be to use a subquery with `distinct`. This might help: http://stackoverflow.com/questions/19577257/wm-concat-with-distinct-clause-compiled-package-versus-stand-alone-query-issue – sgeddes Oct 03 '16 at 01:21
  • Distinct isn't working. This query itself is a subquery. – Annie Jeba Oct 03 '16 at 01:41
  • It's not clear why from your sample data. You should provide sample data that illustrates the problem you are having. Perhaps create a sqlfiddle.com to demonstrate. – sgeddes Oct 03 '16 at 01:43
  • SELECT a ,to_char(c,'DD.MM.YYYY') enddate ,type ,wm_concat( type || ': (' || to_char (c,'HH:MI:SS AM') || ') ' || b ) output FROM table GROUP BY a ,to_char(c,'DD.MM.YYYY') ,type – Annie Jeba Oct 03 '16 at 02:38
  • Is the subquery i'm using – Annie Jeba Oct 03 '16 at 02:39
  • Thank you @sgeddes – Annie Jeba Oct 04 '16 at 02:43

1 Answers1

1

You can use LISTAGG function if you are Oracle 11g+

SELECT a, LISTAGG(b, ' ') WITHIN GROUP (ORDER BY b) as b, c
FROM   yourtable
GROUP BY a,c;
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172
  • Does LISTAGG Function has limit of 4000 characters in Oracle 12c? – Annie Jeba Oct 03 '16 at 03:09
  • 1
    @AnnieJeba Yes when string is longer than 4000 bytes it will limit the result. Check this answer for more info http://stackoverflow.com/questions/13795220/listagg-function-result-of-string-concatenation-is-too-long – Pரதீப் Oct 03 '16 at 03:13