How to test the following SQL script in Oracle 11g -
below script written in oracle 11g:
merge tblbio t using (select e.id, tblduplicate.cpid, e.bdt,e.ln, e.fn tblduplicate, entities trim(e.id) = trim(tblduplicate.id)) source on (t.cpid = source.cpid , trim(t.bdt) = trim(source.bdt)) when matched update set t.id = source.id, t.stat = '4' t.cmp = 'hhcc' , t.thn = '2013' , trim(lower(source.ln)) = trim(lower(t.ln)) , trim(lower(source.fn)) = trim(lower(t.fn)) , nvl(trim(t.bdt), ' ') <> ' ' , t.bdt <> '00000000' , nvl(trim(source.bdt), ' ') <> ' ' , source.bdt <> '00000000' , t.stat <> '4'
due data integrity problem, script once in awhile generate more 1 records. in script generate error. want create validation prior script run. when validation generate more 1 records stop script running. how can that?
i tried write following validation capture record count oracle did not it.
select* tblbio t <----- using (select e.id, tblduplicate.cpid, e.bdt,e.ln, e.fn tblduplicate, entities trim(e.id) = trim(tblduplicate.id)) source on (t.cpid = source.cpid , trim(t.bdt) = trim(source.bdt)) when matched select * tblbio t <----- t.cmp = 'hhcc' , t.thn = '2013' , trim(lower(source.ln)) = trim(lower(t.ln)) , trim(lower(source.fn)) = trim(lower(t.fn)) , nvl(trim(t.bdt), ' ') <> ' ' , t.bdt <> '00000000' , nvl(trim(source.bdt), ' ') <> ' ' , source.bdt <> '00000000' , t.stat <> '4'
converting original merge
query select tbiblio
:
merge ... using
-->select ... join
when matched update set ... where
-->where
final query:
select * tblbio t join (select e.id, tblduplicate.cpid, e.bdt,e.ln, e.fn tblduplicate, entities trim(e.id) = trim(tblduplicate.id)) source on (t.cpid = source.cpid , trim(t.bdt) = trim(source.bdt)) t.cmp = 'hhcc' , t.thn = '2013' , trim(lower(source.ln)) = trim(lower(t.ln)) , trim(lower(source.fn)) = trim(lower(t.fn)) , nvl(trim(t.bdt), ' ') <> ' ' , t.bdt <> '00000000' , nvl(trim(source.bdt), ' ') <> ' ' , source.bdt <> '00000000' , t.stat <> '4'
Comments
Post a Comment