PROBLEM : Automatically assign primary key value using backed Trigger.
SOLUTION : Code.
CREATE OR REPLACE TRIGGER stlbas.dbt_auto_srlnum
BEFORE INSERT
ON stlbas.stbrnlm1
FOR EACH ROW
BEGIN
BEGIN
SELECT COUNT (a.sancid) + 1
INTO :NEW.srlnum
FROM stlbas.stbrnlm1 a
WHERE a.sancid = :NEW.sancid;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
:NEW.srlnum := 1;
WHEN OTHERS
THEN
:NEW.srlnum := 1;
END;
END;
SOLUTION : Code.
CREATE OR REPLACE TRIGGER stlbas.dbt_auto_srlnum
BEFORE INSERT
ON stlbas.stbrnlm1
FOR EACH ROW
BEGIN
BEGIN
SELECT COUNT (a.sancid) + 1
INTO :NEW.srlnum
FROM stlbas.stbrnlm1 a
WHERE a.sancid = :NEW.sancid;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
:NEW.srlnum := 1;
WHEN OTHERS
THEN
:NEW.srlnum := 1;
END;
END;
Comments
Post a Comment