For the last couple of days my head is spinning around this issue and I am really hoping you can help me with this. So simplifying the issue. This is the table I already have:
| ID | Message | Time | Zone |
|---|---|---|---|
| 1 | A | 1PM | PT |
| 1 | B | 1PM | PT |
| 1 | C | 1PM | PT |
| 2 | D | 2AM | FR |
| 2 | E | 2AM | FR |
| 3 | F | 3PM | TK |
I need the following output:
| ID | Message | Time | Zone |
|---|---|---|---|
| 2 | D,E | 2AM | FR |
| 3 | F | 3PM | TK |
I want to concatenate all the messages for the same id in the same field I tried to do this but since the messages for some IDs (example ID 1) are too big and retrieve ORA-01489 “result of string concatenation is too long”. This happens because I have hundreds of lines for the same IDs and concatenating them will make more than 4000 characters, so I want to exclude from the select everything that as a count of the same ID bigger or equal than 3 lines so that doesn’t process and doesn’t retrieve that error.
Right now the oversimplified code is something along the lines of:
Select distinct id,
LISTAGG(CASE when MESSAGE = ‘X’ THEN ‘Z’
ELSE MESSAGE),
TIME,
ZONE
FROM TABLE
Adding a where clause it’s not helping to solve this I think (but really I’m kind of lost here) that the solution must come within the select.
Already tried to do select clauses did not worked, already tried to trim but this is not visual it’s a matter of processing capacity so it also does nothing.