2

How to aggregate string( concatenate) with Oracle 10g SQL?

acroa
  • 3,239
  • 4
  • 17
  • 6
  • 2
    Aggregation and concatenation are not quite the same thing. Which did you mean? – FrustratedWithFormsDesigner Mar 10 '10 at 16:00
  • what I ment was to aggregate where aggregation function is concatenation. let's say data table looks like this: class text A TEXT1 A TEXT2 B TEXT3 B TEXT4 I would like to have group by query select class, function(text) from TABLE group by class that results with something like: A TEXT1, TEXT2 B TEXT3, TEXT4 – acroa Mar 16 '10 at 14:15

5 Answers5

2

You could try the collect function:

http://www.oracle-developer.net/display.php?id=306

Some other tricks are here:

http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

...If you actually mean concatenation instead of aggregation then take everyone else's advice and use the || operator between the two strings:

select 'abc'||'def' from dual;
FrustratedWithFormsDesigner
  • 26,726
  • 31
  • 139
  • 202
1

Oddly enough, it's the "||" operator:

field1 || field2
Mike Mooney
  • 11,729
  • 3
  • 36
  • 42
1

You could use the || operator. Ex: 'First' || 'Second'

Also the function CONCAT(var1, var2) allows you to concatenate two VARCHAR2 characters. Ex: CONCAT('First', 'Second')

Ajadex
  • 2,319
  • 1
  • 20
  • 23
0

There is an undocumented function wm_concat that you can use. Another option would be to roll your own. LISTAGG isn't available in 10g, I think.

SQB
  • 3,926
  • 2
  • 28
  • 49
0

Concatenate: CONCAT or ||

Aggregate: COLLECT

JoeG
  • 12,994
  • 1
  • 38
  • 63