1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

How to delete child record first and then the parent record also

Discussion in 'Oracle Forms and Reports' started by Urosh, May 25, 2013.

  1. Urosh

    Urosh Active Member

    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    80
    Hello,
    I have a form with six blocks based on database tables. First table RESURSI is a parent of the other five tables (ALATI, PRIBORI, ENERGENTI, PRATECI_RES, PREDMETI_RADA)
    In my layout (tabular layout) are only the records from the RESURSI (english - resources) table with one added non-database item (NONDB_TIP_RESURSA) in which I display what kind of resource is it (ALAT, PRIBOR, ENERGENT...it can be only one of the five types of resources).
    What I want to do is to make a button with WHEN-BUTTON-PRESSED trigger that will delete the parent record of my choosing (tabular layout) and with it the child record. I don't want to alter the table constraints I just want to simply delete both records.

    I've tried to do it with this WHEN-BUTTON-PRESSED trigger:

    Code (Text):
    BEGIN
        IF :RESURSI.NONDB_TIP_RESURSA = 'Predmet rada' THEN
            delete from PREDMETI_RADA
            where PREDMETI_RADA.RES_ID_RES = :RESURSI.ID_RES;
        ELSIF :RESURSI.NONDB_TIP_RESURSA = 'Alat' THEN
            delete from ALATI
            where ALATI.RES_ID_RES = :RESURSI.ID_RES;
        ELSIF :RESURSI.NONDB_TIP_RESURSA = 'Energent' THEN
            delete from ENERGENTI
            where ENERGENTI.RES_ID_RES = :RESURSI.ID_RES;
        ELSIF :RESURSI.NONDB_TIP_RESURSA = 'Pribor' THEN
            delete from PRIBORI
            where PRIBORI.RES_ID_RES = :RESURSI.ID_RES;
        ELSE
            delete from PRATECI_RES
            where PRATECI_RES.RES_ID_RES = :RESURSI.ID_RES;
        END IF;
        commit;
        delete_record;
        commit;
        last_record;
    END;
    but I get: DELETE FROM RESURSI WHERE ROWID=:1
    ORA-02292: integrity constraint (AUPS.AL_RES_FK) violated - child record found

    Thanks for helping!
     
  2. ac.arijit

    ac.arijit Forum Advisor

    Messages:
    217
    Likes Received:
    22
    Trophy Points:
    280
    Location:
    Kolkata, India
    Hi Urosh,

    Your approach is fine, but the error indicates that probably when the delete_record is executed it still finds those depending child records. Try and use standard.commit; instead of commit;