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 38 39 40 41 42
| CREATE OR REPLACE TRIGGER NO_CRT_CREDIT
BEFORE INSERT OR UPDATE ON PAIEMENTCREDIT
FOR EACH ROW
DECLARE
Crt NUMBER;
Exist NUMBER;
Aut NUMBER;
BEGIN
Crt := 0;
Exist := 0;
Aut := 0;
SELECT count(nopaiement)
INTO Exist
FROM paiement
WHERE paiement.nopaiement = :new.nopaiement ;
IF (Exist = 0) THEN
RAISE_APPLICATION_ERROR (-20005,'noPaiement invalide (inexistant dans la table Paiement)');
end if;
SELECT count(distinct noclient)
INTO Crt
FROM paiementcredit, paiement, detaillivraison, commande
WHERE paiementcredit.nopaiement = paiement.nopaiement AND
paiement.nolivraison = detaillivraison.nolivraison AND
detaillivraison.nocommande = commande.nocommande AND
nocarte = :new.nocarte;
SELECT count(noautorisation)
INTO Aut
FROM paiementcredit
where noautorisation = :new.noautorisation ;
IF (Crt > 1) THEN
DELETE FROM paiement WHERE nopaiement = :new.nopaiement;
RAISE_APPLICATION_ERROR (-20005,'Carte de credit deja utilisee par un autre client');
elsif (Aut > 0) THEN
DELETE FROM paiement WHERE nopaiement = :new.nopaiement;
RAISE_APPLICATION_ERROR (-20005,'numero autorisation deja utilise pour un autre paiement');
end if;
END; |