select terminal, respuesta, estado, count(*) count, sum(monto) sum from venpeloperacion where respuesta='00' group by terminal, respuesta, estado; select mensaje, decode(respuesta,'00','00','BI','BI','NO'), estado, count(*) count, sum(monto) sum from venpeloperacion group by mensaje, decode(respuesta,'00','00','BI','BI','NO'), estado order by mensaje; select count(*), sum(amount)/100 sum from aprobtrans where responsecode='00'; alter table aprobtrans add(documento number(10)); alter table refusetrans add(documento number(10)); create or replace view aprobtransv as select * from aprobtrans where responsecode='00'; create or replace view refusetransv as select * from refusetrans where responsecode is not null; create or replace view venpelaprov as select * from venpeloperacion where respuesta='00' and mensaje ='A'; create or replace view venpelrefuse as select * from venpeloperacion where respuesta!='00' and mensaje ='A'; declare cursor trans is select documento, terminal, mensaje, fecha, vence, monto, respuesta from venpeloperacion where respuesta is not null and mensaje='A'; cursor aprob(doc in number, terminal in varchar2, fecha in varchar2, vence in varchar2, monto in number) is select systraceno from aprobtrans where terminalid=terminal and amount=monto and expdate=vence and local_date=fecha and responsecode='00' and documento is null order by abs(systraceno-doc) for update of documento; cursor refuse(doc in number, terminal in varchar2, fecha in varchar2, vence in varchar2, resp in varchar2, monto in number) is select systraceno from refusetrans where terminalid=terminal and amount=monto --and expdate=vence and local_date=fecha and responsecode=resp and documento is null order by abs(systraceno-doc) for update of documento; vCuenta number(3); VMOnto number(14,2); begin update aprobtrans set documento=null; for t in trans loop if t.respuesta='00' then for a in aprob(t.documento, t.terminal, to_char(t.fecha, 'MMDD'), t.vence, t.monto*100) loop update aprobtrans set documento=t.documento where current of aprob; exit; end loop; else for a in refuse(t.documento, t.terminal, to_char(t.fecha, 'MMDD'), t.vence, t.respuesta, t.monto*100) loop update refusetrans set documento=t.documento where current of refuse; exit; end loop; end if; end loop; commit; end; / drop table venpeldif; create table venpeldif as select 'A' resultado, nvl(o.terminal, a.terminalid) terminal, o.documento, o.monto, a.systraceno, a.amount/100 amount, a.local_date from venpelaprov o full outer join aprobtransv a on a.terminalid=o.terminal and a.documento=o.documento where nvl(monto,0)!=nvl(amount,0)/100; insert into venpeldif (resultado, terminal, documento, monto, systraceno, amount, local_date) select 'R' mensaje, nvl(o.terminal, a.terminalid) terminal, o.documento, o.monto, a.systraceno, a.amount/100 amount, a.local_date from venpelrefuse o full outer join refusetransv a on a.terminalid=o.terminal and a.documento=o.documento where nvl(monto,0)!=nvl(amount,0)/100; select terminal, documento, monto, systraceno, amount, local_date from venpeldif where resultado='A' order by terminal, nvl(systraceno,documento); select terminal, documento, monto, systraceno, amount from venpeldif where resultado='R'; select sum(monto) montosge, sum(amount) montocre from venpeldif; select d.systraceno, d.amount, o.documento from venpeldif d, venpeloperacion o where d.documento is null and o.terminal=d.terminal and o.monto=d.amount and to_char(o.fecha,'MMDD')=d.local_date and o.estado='P' order by systraceno; CREDOMATIC PERO NO LLOBET TERMINAL DOCUMENTO MONTO SYSTRA AMOUNT -------- --------- --------- ------ --------- LLOBET01 000003 407,5 LLOBET01 000005 203,75 LLOBET01 000307 8850 LLOBET06 000058 6160 LLOBET06 000059 6160 LLOBET06 000060 6160 LLOBET06 000061 6160 LLOBET06 000062 6160 LLOBET06 000063 6160 LLOBET06 000064 6160 LLOBET06 000066 6160 LLOBET08 000082 4950 LLOBET08 000083 20000 LLOBET13 000132 8925 LLOBET15 000057 28500 LLOBET15 000058 28500 LLOBET15 000059 28500 LLOBET15 000060 28500 LLOBET18 000037 17605,12 LLOBET27 000013 6750 LLOBET27 000014 6750 LLOBET27 000016 6750 LLOBET30 000001 815 --------- 245286,37 TOTALES APROBACION COUNT SUM --------- --------- LLO 2663 43012854 CRE 2686 43258141 ------------------- DIF 245287 select * from refusetrans where responsecode='00'; select terminal, documento, respuesta, fecha, vence, monto from venpeloperacion where mensaje='A' and monto=27731.25; select terminalid, systraceno, responsecode, local_date, expdate, amount/100 from refusetrans where amount/100=27731.25 union select terminalid, systraceno, responsecode, local_date, expdate, amount/100 from aprobtrans where amount/100=27731.25; select terminalid, expdate, local_date, systraceno, responsecode, documento from refusetrans where amount=817500; select terminal, documento, tarjeta, banda, monto from venpeloperacion where mensaje='A' and respuesta='BI'; select terminal, documento, tarjeta, banda, monto from venpeloperacion where mensaje='A' and respuesta='00' and banda is null; select fecha, terminal, documento, tarjeta, banda, monto from venpeloperacion where mensaje='A' and respuesta is null and terminal='LLOBET01' order by fecha; select terminal, fecha, documento, tarjeta, banda, monto from venpeloperacion where mensaje='R' order by fecha;