Skip to content
Advertisement

How to create a query to get the multiple row data in comma separated format in one row in Oracle

I have a requirement where I have column ‘NOTECODE’ in database table POLICY which contains multiple Note Codes in comma separated format. Ex: CC,TD,HL

POLICY :

ALSO there is a CODEDESC table which contains the description as below

I want to fetch data using query which gives the POLICYNO, NOTECODE and DESCRIPTION as mentioned below:

How can I do it?

Advertisement

Answer

You can use JOIN and aggregation:

Note that this is not efficient! This is a work-around because you are stuck with a really bad data model. Your efforts should really be to fix the data model.

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