您可以取消配对的列,只过滤不同的列。
select id, fatherid, field, o before, n after
from (
select n.id, n.fatherid, n.a na, o.a oa, n.b nb, o.b ob,
to_char(n.c) nc, to_char(o.c) oc,
to_char(n.d) nd, to_char(o.d) od
from t n join t o on n.fatherid = o.id)
unpivot ((n, o) for field in ((na, oa) as ‘A’, (nb, ob) as ‘B’,
(nc, oc) as ‘C’, (nd, od) as ‘D’))
where n <> o or (n is null and o is not null) or (n is not null and o is null)
order by id, field
</code>
的
演示样本数据
</强>
ID FATHERID FIELD BEFORE AFTER
2457 5678 A Mark Chris
2457 5678 D 20170804 20180402
4554 1234 B Doe Dee
4554 1234 C 15 25
</code>
您必须列出所有列,将它们转换为字符。很多工作,错误的空间,但这是我提出的最好的。