Concatenate varchar2 PLSQL

0

I have 2 tables with relationship 1 to many and I need to concatenate all values of column Nome of table 2 in only one column of select.

Eg:

In the example, the return of what I need would be Maria, João, José

Note: The database is PLSQL.

    
asked by anonymous 14.06.2018 / 14:09

1 answer

1

Jonathan I found a great example of this site link

I have the following table:

Customer Product Code 1 Jorge piso 1 Jorge porta 1 Jorge faucet

I need the result of this select to look like this:

Customer Product Code 1 Jorge floor, door, faucet

- Concatenating

SELECT  CODIGO,
        CLIENTE,
    COALESCE(
        (SELECT CAST(PRODUTO AS VARCHAR(10)) + ';' AS [text()]
         FROM TABELA AS O
         WHERE O.CODIGO  = C.CODIGO
         and   O.CLIENTE = C.CLIENTE
         ORDER BY CODIGO
         FOR XML PATH(''), TYPE).value('.[1]', 'VARCHAR(MAX)'), '') AS Produtos
FROM TABELA AS C
GROUP BY CODIGO,CLIENTE;
    
14.06.2018 / 14:18