1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| CREATE OR REPLACE PROCEDURE gg IS
NDB NUMBER(15,3);
MDB NUMBER(15,3);
MCR NUMBER(15,3);
NCR NUMBER(15,3);
mt NUMBER(15,3);
sns VARCHAR2(2 BYTE);
BEGIN
select sum(montant),count(*) into MDB,NDB from tst where num_compte='0668236211000100' and sens='DB' and to_char(date_operation,'mm')='01';
select sum(montant),count(*) into MCR,NCR from tst where num_compte='0668236211000100' and sens='CR' and to_char(date_operation,'mm')='01';
if MCR is null
then MCR :=0;
end if;
if MDB is null
then MDB :=0;
end if;
mt :=MCR-MDB;
IF mt < 0
then sns :='DB' ;
mt:=(-1)*mt;
else sns :='CR';
end if;
insert into tst1 (num_compte,montant,sens,mois,nbodb,nbocr) values ('0668236211000100',(mt),(sns),to_char(sysdate,'mm')-1,ndb,ncr);
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END gg;
/ |
Partager