Skip to content
Advertisement

How to use wm_concat one a column that already exists in the query?

So… I am currently using Oracle 11.1g and I need to create a query that uses the ID and CusCODE from Table_with_value and checks Table_with_status using the ID to find active CO_status but on different CusCODE.

This is what I have so far – obviously does not work as it should unless CusCODE and ID are provided manually:

Table_with_value:

Table_with_status:

Expected output:

Any idea on how this can be implemented ideally without any PL/SQL for loops, but it should be fine as well since the output dataset is expected < 300 IDs.

I apologize in advance for the cryptic nature in which I structured the question 🙂 Let me know if something is not clear.

Advertisement

Answer

From your description and expected output, it looks like you need a left outer join, something like:

SQL Fiddle using listagg() instead of the never-supported and now-removed wm_concat(); with a couple of different approaches if the logic isn’t quite what I interpreted. With your sample data they all get:

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