Hi there,
I'm posting a message in this forum in order to get some help. I'm working on a database which has been developped by someone and I've some difficulties to insert a new unique barcode in my table ressource.
Actually, I've 2 tables : barcode and ressource. I understand that barcode is there to generate a new barcode which is link to Ressource with the barcode_id. I don't manage to insert new values in my Barcode table. How the barcode is automatically inseted into ressource ?
For example :
Barcode
id
37465
SECTOR
D
YEAR
3
PREFIX
58
Ressource
Barcode |
barcode_id
D03000058 37465
I've also a trigger but I don't know how to use it.
create or replace TRIGGER "TBB".TOB_BARCODE
BEFORE INSERT OR UPDATE ON BARCODE
FOR EACH ROW
DECLARE
integrity_error exception;
errno integer;
errmsg char(200);
BEGIN
-- autoincrement
IF INSERTING THEN
BEGIN
SELECT S_BARCODE.NEXTVAL INTO :NEW.ID FROM dual;
EXCEPTION
WHEN integrity_error THEN
raise_application_error(errno, errmsg);
END;
END IF;
BEGIN
-- calculated row BARCODE of RESSOURCE table
UPDATE RESSOURCE SET BARCODE = :NEW.SECTOR || TO_CHAR(:NEW.YEAR,'FM00') || TO_CHAR(:NEW.PREFIX,'FM00000') ||
DECODE(:NEW.CATEGORY, 2, 'E', 3, 'D', NULL,'','') || TO_CHAR(:NEW.SUFFIX,'FM00')
WHERE BARCODE_ID = :NEW.ID ;
EXCEPTION
WHEN OTHERS THEN NULL;
END;
END;