1
I have a query that involves several tables in Oracle, and returns a large number of columns. I wanted instead of returning the records of this query, return me the columns of select as records.
An example of how more or less the current query is:
SELECT
tab1.campo1 'tab1.campo1',
tab1.campo2 'tab1.campo2',
tab1.campo3 'tab1.campo3',
tab2.campo1 'tab2.campo1',
tab2.campo2 'tab2.campo2',
tab2.campo3 'tab2.campo3',
tab3.campo1 'tab3.campo1',
tab3.campo2 'tab3.campo2',
tab3.campo3 'tab3.campo3',
tab4.campo1 'tab4.campo1',
tab4.campo2 'tab4.campo2',
tab4.campo3 'tab4.campo3'
FROM
tabela1 tab1,
tabela2 tab2,
tabela3 tab3,
tabela4 tab4
WHERE
tab1.campo2 = tab2.campo1
and tab2.campo3 = tab4.campo1
and tab1.campo3 = tab3.campo1
Again, I need to list these columns as rows.
I tried to use Unpivot, but to no avail.
See if it helps, http://answall.com/questions/104776/convers%C3%A3o-e-grouping-of-rows-in-columns-dynamically-in-oracle
– David
These examples are not in Oracle, but may help you: 1 - http://answall.com/questions/135025/como-converter-resultado-de-searchno-mysql-em-colunas/135035#135035 2 - http://answall.com/questions/131780/como-transfomar-a-linha-de-a-table-in-column/131796#131796
– Emerson JS
Both helped. I managed to list something. Thank you.
– Alexandre
@Alexandre, could add the solution as an answer to the problem?
– David
SELECT COLUNA1 FROM TABELA1 UNION SELECT COLUNA2 FROM TABELA1 UNION ... SELECT COLUNAN FROM TABELA1 UNION SELECT COLUNA1 FROM TABELAN ,... UNION SELECT COLUNAN FROM TABELAN
– Motta