Trigger that validates the percentage of each tranche in a purchase note greater than x value

Asked

Viewed 34 times

2

Good morning, I’m having a hard time creating a Rigger that checks on the Insert and update a higher apportionment number than x ( I’m using 30 for testing) on each purchase note. This is the first Trigger I’ve created in my life so I don’t know if the code I’m posting has anything to do with it. We work with Oracle, there is a table called TGFRAT where it stores the values of grading of the note having NUFIN that would be the number of the note, PERCRAT is the percentage of apportioning used and that needs to be validated, where the value can be divided into several cost centers, and ORIGIN which is a string field that needs to receive 'E'. I need Rigger to validate if the sum of all the rates in the note is more than 30 , and can be divided into several cost centres. I’m sorry if the explanation became hard to understand, but it’s because it’s really the first time I’ve ever done a Rigger. Thanks for your attention.

BEFORE INSERT OR UPDATE ON TGFRAT  
FOR EACH ROW 
     DECLARE P_NUFIN       INTEGER;
            P_PERCRATEIO   FLOAT;
            P_ORIGEM      CHAR(1);
BEGIN 
    P_NUFIN =  NEW.NUFIN
    P_PERCRATEIO = NEW.PERCRATEIO
    P_ORIGEM = NEW.ORIGEM
    SELECT COUNT(*) INTO P_PERCRATEIO  FROM TGFRAT WHERE NUFIN = P_NUFIN AND ORIGEM = P_ORIGEM;
IF
    (P_PERCATEIO >30) THEN ' ERROR'
END IF;

IF
    P_ORIGEM <> 'E' THEN ' ORIGEM ERROR'
END IF;
END ```

  

  • I don’t understand these IF. You want to assign these strings to some field?

  • So I want it to validate whether the ORIGIN is receiving 'E' and whether the PERCRATEIO is greater than 30. Like I said, I never did a Trigger, so I looked at the ones in the bank to serve as a base.

    1. should be sum(PERCRAT) instead of Count(*) , I believe. But even so I believe that Trigger will fall into "Mutating Table" which is a complicated gentleman https://www.oracletutorial.com/plsql-tutorial/mutating-table-error-in-oracle/
  • Thanks for the tip, buddy. I’ll follow what you sent me

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.