I have two tables table A(master table)- 250 columns and table b(history table)- 240 columns, I need to create dynamic query as i table have 250 columns. using oracle
suppose: Table A(Master table)
ID Name City Phone Category
---------------------------------------
111 ABC Delhi 123456 Red
112 BCD Mumbai 234987 Green
113 CGU PUNE 987456 Black
suppose: Table B(History table)
ID City Phone Category
---------------------------------
111 Kerala 123456 White
113 Jammu 577756 Black
I need output something like that
ID changes column name Old_value new_value
----------------------------------------------------------
111 City Kerala Delhi
111 Category White Red
113 City Jammu Pune
113 Phone 987456 577756
but This is not dynamic i am using oracle
select distinct
hist.ID,
'city' as Changed_Column,
hist.cityas Old_Value,
daily.cityas New_Value
from table A dly daily
inner join table b hist on daily.ID= hist.ID
and daily.city <> hist.city