CassidyHunt
IS-IT--Management
I need to modify a trigger in my database. Before data is inserted into the table I need to see if it violates a constraint on the table. If it does then instead of inserting it I need it to update the existing row with the new data.
Currently the trigger looks like this:
The constraint I am testing looks like this:
The table looks like this:
Thanks for all the help.
Cassidy
Currently the trigger looks like this:
Code:
CREATE OR REPLACE TRIGGER TBIUD_INVDIST_ROW
BEFORE INSERT OR DELETE OR UPDATE
ON INV_TRANS_DIST
REFERENCING NEW AS NEWDATA OLD AS OLDDATA
FOR EACH ROW
BEGIN
IF DELETING THEN
plsql_INV_TRANS_DIST.ENTRIES := plsql_INV_TRANS_DIST.ENTRIES + 1;
plsql_INV_TRANS_DIST.table_IN_TRANS_ID(plsql_INV_TRANS_DIST.ENTRIES) := :OLDDATA.IN_TRANS_ID;
plsql_INV_TRANS_DIST.table_OUT_TRANS_ID(plsql_INV_TRANS_DIST.ENTRIES) := :OLDDATA.OUT_TRANS_ID;
plsql_INV_TRANS_DIST.table_DIST_QTY(plsql_INV_TRANS_DIST.ENTRIES) := (:OLDDATA.DIST_QTY * -1);
plsql_INV_TRANS_DIST.table_DEMAND_SUPPLY_ID(plsql_INV_TRANS_DIST.ENTRIES) := :OLDDATA.DEMAND_SUPPLY_ID;
END IF;
IF UPDATING THEN
plsql_INV_TRANS_DIST.ENTRIES := plsql_INV_TRANS_DIST.ENTRIES + 1;
plsql_INV_TRANS_DIST.table_IN_TRANS_ID(plsql_INV_TRANS_DIST.ENTRIES) := :NEWDATA.IN_TRANS_ID;
plsql_INV_TRANS_DIST.table_OUT_TRANS_ID(plsql_INV_TRANS_DIST.ENTRIES) := :NEWDATA.OUT_TRANS_ID;
plsql_INV_TRANS_DIST.table_DIST_QTY(plsql_INV_TRANS_DIST.ENTRIES) := :NEWDATA.DIST_QTY - :OLDDATA.DIST_QTY;
plsql_INV_TRANS_DIST.table_DEMAND_SUPPLY_ID(plsql_INV_TRANS_DIST.ENTRIES) := :NEWDATA.DEMAND_SUPPLY_ID;
END IF;
IF INSERTING THEN
plsql_INV_TRANS_DIST.ENTRIES := plsql_INV_TRANS_DIST.ENTRIES + 1;
plsql_INV_TRANS_DIST.table_IN_TRANS_ID(plsql_INV_TRANS_DIST.ENTRIES) := :NEWDATA.IN_TRANS_ID;
plsql_INV_TRANS_DIST.table_OUT_TRANS_ID(plsql_INV_TRANS_DIST.ENTRIES) := :NEWDATA.OUT_TRANS_ID;
plsql_INV_TRANS_DIST.table_DIST_QTY(plsql_INV_TRANS_DIST.ENTRIES) := :NEWDATA.DIST_QTY;
plsql_INV_TRANS_DIST.table_DEMAND_SUPPLY_ID(plsql_INV_TRANS_DIST.ENTRIES) := :NEWDATA.DEMAND_SUPPLY_ID;
END IF;
END;
The constraint I am testing looks like this:
Code:
create unique index SYS_C002119_2 on INV_TRANS_DIST (IN_TRANS_ID, OUT_TRANS_ID)
tablespace USER_INDEX
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 9M
minextents 1
maxextents unlimited
);
The table looks like this:
Code:
create table INV_TRANS_DIST
(
IN_TRANS_ID INTEGER not null,
OUT_TRANS_ID INTEGER not null,
DIST_QTY NUMBER(14,4) not null,
ACT_MATERIAL_COST NUMBER(15,2) default 0 not null,
ACT_LABOR_COST NUMBER(15,2) default 0 not null,
ACT_BURDEN_COST NUMBER(15,2) default 0 not null,
ACT_SERVICE_COST NUMBER(15,2) default 0 not null,
DEMAND_SUPPLY_ID INTEGER
)
Thanks for all the help.
Cassidy