Hi,
we're trying to create a trigger to perform a check on existing rows in a table when an insert statement occurs...
but we don't know how the external variables are passed to this procedure....
the code that provide that control looks like:
create or replace trigger my_trigger
BEFORE INSERT ON my_table
FOR EACH ROW
DECLARE
var1 CHAR(02);
var2 BOOLEAN;
BEGIN
SELECT col1 INTO var1
FROM my_table
WHERE col1 = :NEW.col1
AND col2 = :NEW.col2
AND col3 = :NEW.col3
AND col4 = :NEW.col4
AND col5 = :NEW.col5
AND col6 = :NEW.col6;
EXCEPTION
WHEN NO_DATA_FOUND THEN
INSERT INTO my_table
VALUESNEW.col1, :NEW.col2, :NEW.col3,
:NEW.col4, :NEW.col5, :NEW.col6);
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-my_err_num, 'my_err_msg');
END;
after compiling and validating this trigger we've tried to perform an insert statement but the check doesn't work...
so we're able to insert duplicated rows
Any idea will be appreciate.
Thanks for your support.
Best regards Roberto
we're trying to create a trigger to perform a check on existing rows in a table when an insert statement occurs...
but we don't know how the external variables are passed to this procedure....
the code that provide that control looks like:
create or replace trigger my_trigger
BEFORE INSERT ON my_table
FOR EACH ROW
DECLARE
var1 CHAR(02);
var2 BOOLEAN;
BEGIN
SELECT col1 INTO var1
FROM my_table
WHERE col1 = :NEW.col1
AND col2 = :NEW.col2
AND col3 = :NEW.col3
AND col4 = :NEW.col4
AND col5 = :NEW.col5
AND col6 = :NEW.col6;
EXCEPTION
WHEN NO_DATA_FOUND THEN
INSERT INTO my_table
VALUESNEW.col1, :NEW.col2, :NEW.col3,
:NEW.col4, :NEW.col5, :NEW.col6);
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-my_err_num, 'my_err_msg');
END;
after compiling and validating this trigger we've tried to perform an insert statement but the check doesn't work...
so we're able to insert duplicated rows
Any idea will be appreciate.
Thanks for your support.
Best regards Roberto