I'm new at PL/SQL. I'm trying to program a trigger
that insert
in a table
A just if there is an insert
in table
B (to have an insert in table B, the following select
must returns 1).
SELECT 1
INTO v_exists
FROM TFRG V
WHERE
SUBSTR(:NEW.COD_OBJT, 1, 2) = V.CDP
AND SUBSTR(:NEW.COD_OBJT, 12, 2) = V.CDS
AND V.CDSIT = 'V'
AND V.CDG IN (‘E’,’G’);
The problem is that I don't know how to include this select in my trigger:
CREATE OR REPLACE TRIGGER Trigger_name
-- PL/SQL Block
AFTER INSERT
ON B FOR EACH ROW
declare
v_exists NUMBER;
begin
begin
SELECT 1
INTO v_exists
FROM TFRG V
WHERE
SUBSTR(:NEW.COD_OBJT, 1, 2) = V.CDP
AND SUBSTR(:NEW.COD_OBJT, 12, 2) = V.CDS
AND V.CDSIT = 'V'
AND V.CDG IN (‘E’,’G’);
INSERT INTO A
(NR);
VALUES
(:new.objt);
exception
when NO_DATA_FOUND then
null;
end;
exception
when OTHERS then
null;
END