Wednesday, March 25, 2009

CDC QUERY IN ORACLE

desc table



update test_update u
set (u.changec) =
(
with t as
(select change,x.c1 as c1,x.c2 as c2,x.c3 as c3,x.c4 as c4,x.c5 as c5,x.c6 as c6 from test_update x,
(
(select
'c4 change' as change ,a.c1,a.c2,a.c3,a.c4,a.c5,a.c6
from test_update a,test_update b
where
a.c1=b.c1 and
a.c2=b.c2 and
a.c3=b.c3 and
( a.c4 != b.c4 )
and a.sourceI='I')
union
(select
'c5 change' as change,a.c1,a.c2,a.c3,a.c4,a.c5,a.c6
from test_update a,test_update b
where
a.c1=b.c1 and
a.c2=b.c2 and
a.c3=b.c3 and
(a.c5 != b.c5 )
and a.sourceI='I'))y
where
X.C1=y.c1 and
x.c2=y.c2 and
x.c3=y.c3
and x.sourceI='I')
select change from t
where t.c1=u.c1 and
t.c2=u.c2 and
t.c3=u.c3 and
t.c4=u.c4 and
t.c5=u.c5 and
t.c6=u.c6
-- t.sourceI='I'
)