I have a very long query, across multiple tables, where I have concatenated four values as owners (first, middle and last name + org). All other columns are the same, but there are multiple owners, thus, multiple rows which I would like to aggregate.
What I am seeing is (paired down)
# Owner
1 Sam Smith, AAA
2 Stan Bird, BBB
2 Nancy Bird, BBB
3 Mike Owen, CCC
What I would like to see is
# Owner
1 Sam Smith, AAA
2 Stan Bird, Nancy Bird, BBB
3 Mike Owen, CCC
Caveats:
- I can not create functions (lack of privileges)
- Using Oracle 10g
I have attempted
CASE(COLLECT...
but this kills my connection:Error- "No more data to read from socket"
SysAdmin, isn't sure why
- WM_CONCAT simply repeats one owner (sometimes 20 times) and is not giving the desired result.
I have tried a few other things, with no luck. My current query is producing the desired number of rows, but is just lopping off the second owner.
I am unsure if it would be wise to post the entire query here. Please let me know if this would be helpful.
Update 2012-01-29
I was using wm_concat
incorrectly before, but when I use it as you have shown, I am getting this error:
ORA-06502: PL/SQL: numeric or value error: character string buffer too
small ORA-06512: at "WMSYS.WM_CONCAT_IMPL", line 30
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause:
*Action:
I believe there may be some higher level issues at play. My sysadmin had no answer for the "No more data to read from socket" issue. Could this be another.
My SQL knowledge is limited, and with the length and complexity of the query, I can't seem to implement the sys_connect_by_path
; completely my own fault.
Sorry about the delayed response. I was pulled away to complete another task. Thank you for all of your help. Thank you ShadowWizard for the bounty.
EDIT
Here is how I have used wm_concat
in the current instance:
replace(cast(wm_concat(PERSON.MASTER_PERSON_FIRST_NAME || ' ' ||
PERSON.MASTER_PERSON_MIDDLE_INITIAL || ' ' ||
PERSON.MASTER_PERSON_LAST_NAME || ',' || ' ' ||
ORGANIZATION.MASTER_ORG_NAME) AS VARCHAR2(1000 BYTE)), ',', ', ') AS
"Owner(s)",
Sorry, forgot to include that.