Good day! I had to run into Oracle, but I’m a novice developer and ask strictly not to judge my code. When creating a document in the FORMS table, the following trigger is triggered:
CREATE OR REPLACE TRIGGER "REA"."AUTOCREATE_TRIGGER" BEFORE INSERT ON REA.FORMS FOR each ROW WHEN (NEW.LIST_OF_FORMS_ID=59 OR NEW.LIST_OF_FORMS_ID=60) BEGIN IF :NEW.LIST_OF_FORMS_ID=59 THEN AUTOCREATE.AUTOCREATE_PR340_FR73_S1_T1(:NEW.POWER_FACILITIES_VID, :NEW.ID); END As you can see, the trigger calls a procedure that creates subdocuments and adds entries to the PR340_FR73_S1_T1 table and all subdocuments have a FORMS_ID that is associated with the ID in the FORMS table
PROCEDURE AUTOCREATE_PR340_FR73_S1_T1( POWERFACILITIES NUMBER, FORMSID NUMBER) AS BEGIN FOR ROW IN (SELECT VID FROM poe_steam_turbines WHERE POWER_FACILITIES_VID = POWERFACILITIES AND IS_ACTUAL = 1) LOOP INSERT INTO PR340_FR73_S1_T1 ( HAS_PROLONGATION ----ПРОДЛЕНИЕ ,HAS_REMARKING ---ПЕРЕМАРКИРОВКА ,HAS_REPLACEMENT --ЗАМЕНА ,HAS_REMOVAL --ВЫВОД ,POE_STEAM_TURBINES_VID ,FORMS_ID ) VALUES ( 0 ,0 ,0 ,0 ,ROW.VID ,FORMSID ); END LOOP; END AUTOCREATE_PR340_FR73_S1_T1; And at the moment of insertion into the table PR340_FR73_S1_T1, the trigger is triggered.
CREATE OR REPLACE TRIGGER "PR340_FR73_S1_T1_EVENT" BEFORE INSERT ON PR340_FR73_S1_T1 FOR EACH ROW DECLARE period NUMBER; BEGIN SELECT PERIOD_ID INTO period FROM FORMS WHERE Id = :NEW.FORMS_ID; -- в этом запросе происходит ошибка из за :NEW.FORMS_ID --period:=2016; IF :NEW.HAS_REMOVAL = 0 THEN FILL_EVENT.FILL_REMOVAL_ATR(:NEW.POE_STEAM_TURBINES_VID, period, :NEW.STOP_ID, :NEW.REMOVAL_LAST_YEAR); END IF; END; If the period variable is hard-coded, then everything is fine, or if instead of: NEW.FORMS_ID to substitute the value from another existing record, then also the norms, I think that all the same a new record is still created and I cannot get values from it, since all the triggers are before, but how then can I get this value from the new FORMS table entry, before adding the record to the database, changing the trigger in AFTER only caused a lot of errors. Thanks for attention...
for each rowtriggers. Standard solution: create another table. In theAFTER INSERT ON FORMS FOR each ROWtrigger, write two fields in this table:NEW.POWER_FACILITIES_VID, :NEW.IDYou make another trigger on FORMS, but withoutfor each rowin it, read this table and call your procedure. Clear the table - Mikefor each rowtriggers have ended). The decision in the post above will help you for sure - Mike