Skip to content
Advertisement

Oracle move strings to another matching row

I have a table called tblrespondent and my data looks like this:

I have several case numbers that have multiple rows like this and I need to move all the comments into the lowest orclid13. The result would look like this with a semicolon in between each comment.

How would I approach this? Many thanks in advance!

Advertisement

Answer

Assuming you need a select query, this could be a way:

Basically, listagg aggregates all the comments into a single string, row_number() is used to determine whether you are on the first row of the casenm set and this result is used by the case to show the concatenated string only in the first row of the set.

If you need to update your table, you can use the same logic above in a merge:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement