I have an Oracle Form which allows users to add more than one record into a table for a given person. Each person in the database is supposed to be allowed one and only one record. The simple solution was to use the person's ID as a primary key when the table was created. Unfortunately, the table was created with no primary key and has been in production this way for a few years. I cannot go back and add the primary key now because I may corrupt existing data. My problem is I need to change the form, probably using triggers, to act like it has the primary key. I hope that makes sense.
I have tried this trigger, using PRE_INSERT and ON-INSERT at the datablock level:
BEGIN
DECLARE
TEMP NUMBER;
BEGIN
SELECT COUNT(PERSON_ID) INTO TEMP
FROM MYTABLE
WHERE PERSON_ID = ERSON_ID;
IF TEMP > 0 THEN
MESSAGE('*ERROR* Student already has a record in MYTABLE.');
:FORM_FIELD := '';
RAISE FORM_TRIGGER_FAILURE;
END IF;
END;
END;
PERSON_ID is the Person's ID and should have been the primary key for the MYTABLE table. In the datablock, however, it is invisible, pre-filled from the KEY_BLOCK. FORM_FIELD is the field where the cursor lands when entering the datablock and where the actions occur.
So, my question is, does anyone know how to use triggers (or properties) to make a form act like there is a primary key in the underlying table when there isn't one?
I have tried this trigger, using PRE_INSERT and ON-INSERT at the datablock level:
BEGIN
DECLARE
TEMP NUMBER;
BEGIN
SELECT COUNT(PERSON_ID) INTO TEMP
FROM MYTABLE
WHERE PERSON_ID = ERSON_ID;
IF TEMP > 0 THEN
MESSAGE('*ERROR* Student already has a record in MYTABLE.');
:FORM_FIELD := '';
RAISE FORM_TRIGGER_FAILURE;
END IF;
END;
END;
PERSON_ID is the Person's ID and should have been the primary key for the MYTABLE table. In the datablock, however, it is invisible, pre-filled from the KEY_BLOCK. FORM_FIELD is the field where the cursor lands when entering the datablock and where the actions occur.
So, my question is, does anyone know how to use triggers (or properties) to make a form act like there is a primary key in the underlying table when there isn't one?