Delete Trigger

Hi,
I got a question using triggers. I have a statement level delete trigger that calls a package function used to insert data into various archiving tables. In order to keep track of the deleted rows I have a row level delete trigger that keeps the deleted Ids of my objects in a special table that I later query in my statement level trigger.
My main problem is that while all triggers are called properly and data is removed from desired tables, the data that should be inserted into my archiving tables does not appear until the trigger is fired again it appears. I don't really see what could cause data to be deleted and effectively removed while the data i want to insert does not appear until the next time the trigger is fired.
could it be that i need to explicitely commit the inserted data ?
If it's not clear, I could always post some of the code used.
Thanks,
Greg

Sure (I hope it won't be too messy though).
---- PACKAGE DEF.
I have a package variable defined as follows:
TYPE idTable IS TABLE OF NUMBER(19) INDEX BY BINARY_INTEGER;
And my variables:
del_oldRows idTable;
del_emptyRows idTable;
---- PACKAGE BODY
In the body I have calls like this:
PROCEDURE delete_transaction(aID NUMBER) IS
BEGIN
-- I) Add New Data into appropriate archiving tables
-- 1) Many-to-Many Table for first object
INSERT ALL INTO X_OBJ1_OBJ2_DLTD
DLTD_ID,
OBJ1_ID,
OBJ2_ID
SELECT
ID,
OBJ1_ID,
OBJ2_ID
FROM X_OBJ1_OBJ2
WHERE (X_OBJ1_OBJ2.ID = aID )
-- 2) Second object <SNIP>
-- 1) Many-to-Many Table for first object
DELETE FROM X_OBJ1_OBJ2
WHERE (X_OBJ1_OBJ2.ID = aID );
END delete_transaction;
---- Before Delete Trigger (Statement Level)
This one resets the package in a consistent state:
BEGIN
mypackage.del_oldRows := mypackage.del_gatetrans_emptyRows;
END;
---- After Delete Trigger (Row Level)
This one adds Ids in my package variable:
BEGIN
mypackage.del_oldRows(mypackage.del_oldRows.COUNT + 1) := :OLD.ID;
END;
---- After Delete Trigger (Statement)
This one goes through each row in my package "table" and calls the function to add the related data in my archiving table:
BEGIN
FOR i IN 1 .. mypackage.del_oldRows.COUNT LOOP
mypackage.delete_transaction(mypackage.del_oldRows(i));
END LOOP;
mypackage.del_oldRows := mypackage.del_emptyRows;
END;
---- END
Anyways that's the basic logic. Kinda what is suggested for mutating tables when playing with UPDATE triggers I guess. Here it's just because I want my triggers to be simple and focus on inserting the archiving data for the object triggering the... trigger while related objects that need to be archived should be taken care of in my package function. My problem is that the data is removed properly but not appears as inserted until the next time the trigger is fired, as if i was always "one" trigger late :(.
If it's not clear enough, please let me know.
Thanks,
Greg

Similar Messages

  • Get Current SQL in Before delete trigger

    Hi,
    I have created a before delete trigger to track which records are deleted from a table I need to know what statements fires the trigger. can someone please describe how I can retrieve the current SQL.
    using sys_context('userenv','CURRENT_SQL') returns null for CURRENT SQL
    Note:
    For me the easier is to enable auditing and audit delete on the table however at the moment I cant get a downtime from the business to bounce the database to enable auditing.
    CREATE OR REPLACE TRIGGER before_delete BEFORE DELETE
    ON AUDIT_TEST_TAB
    FOR EACH ROW
    DECLARE
    v_username varchar2(50);
    v_stmt varchar2(255);
    v_client_info varchar2(200);
    v_os_user varchar2(50);
    v_machine varchar2(50);
    v_program varchar2(50);
    v_module varchar2(50);
    v_auth_type varchar2(200);
    v_ip_addr varchar2(200);
    v_sql_statement VARCHAR2(4000);
    BEGIN
    SELECT sys_context ('USERENV', 'CURRENT_SQL')
    INTO v_sql_statement
    FROM dual;
    -----------insert into logging table statment ----
    end;

    A few comments.
    Lets assume you run a delete statement that deletes 550 rows from your table. If your trigger is working then the very same statement would be stored 550 times. I think an BEFORE or better an AFTER delete STATEMENT level trigger would be the better choice. Why AFTER? Because if the delete operation fails, for example because of existing child records, then everything is rolled back anyway to the implicit savepoint just before the delete.
    So to store the SQL statement the correct trigger would be an AFTER STATEMENT DELETE trigger.
    Now what to store: You want the sql statement. You could try to find the cursor/currently running SQL. It might be tricky to separate that from the SQLs that you run to find this out.
    It could even be possible to simply save all commands that are in your PGA/Cached cursor area. First find out yur session, then store the SQL_text (first 60 chars) for all the cursors in this session by using v$open_cursor or the first 1000 chars by using v$sql.
    Here are a few views that might be helpful. v$session , v$open_cursor, v$sql, v$sqltext, v$sql_bind_data, v$sql_bind_capture, dba_hist_sqltext

  • :NEW cannot be used in After Delete Trigger ?

    Hi,
    Is there any way to get the :NW.value in the After delete trigger for each row. My requirement is audit log of the end user DML operations along with user Name (HERE THE USER IS NOT THE ORACLE USER, BECAUSE OF THE LARGE NUMBER OF END USERS WE ARE MAINTAINING ONE TABLE TO CREATE USER NAME & PASSWORD, WHEN THE USER LOGIN TO ORACLE FORM SCREEN, ASSIGN THE USER NAME TO GLOBAL VARIABLE) & Action Date.
    Here is my code for trigger - It is working fine with INSER & UPDATE but for DELETE User is NULL
    CREATE OR REPLACE TRIGGER Tgr_stud_det
    AFTER INSERT OR UPDATE OR DELETE ON student_details
    FOR EACH ROW
    DECLARE
    BEGIN
    IF Inserting THEN
    -------------INSERT VALUE---------------
    INSERT INTO Log_student_details
    (Seq,
    App_User,
    Action,
    Action_Date,
    stud_name,
    stud_age,
    stud_sex)
    VALUES
    (stud_sequence.NEXTVAL,
    :NEW.App_User,
    'INSERT',
    SYSDATE,
    :NEW.stud_name,
    :NEW.stud_age,
    :NEW.stud_sex);
    -------------DELETE VALUE---------------
    ELSIF Deleting THEN
    INSERT INTO Log_student_details
    (Seq,
    App_User,
    Action,
    Action_Date,
    Comment_Up,
    stud_name,
    stud_age,
    stud_sex)
    VALUES
    (stud_sequence.NEXTVAL,
    :OLD.App_User,
    'DELETE',
    SYSDATE,
    NULL,
    :OLD.stud_name,
    :OLD.stud_age,
    :OLD.stud_sex);
    ELSIF Updating THEN
    -------------UPDATE VALUE---------------
    INSERT INTO Log_student_details
    (Seq,
    App_User,
    Action,
    Action_Date,
    Comment_Up,
    stud_name,
    stud_age,
    stud_sex)
    VALUES
    (stud_sequence.NEXTVAL,
    :NEW.App_User,
    'UPDATE',
    SYSDATE,
    'NEW VALUE',
    :NEW.stud_name,
    :NEW.stud_age,
    :NEW.stud_sex);
    INSERT INTO Log_student_details
    (Seq,
    App_User,
    Action,
    Action_Date,
    Comment_Up,
    stud_name,
    stud_age,
    stud_sex)
    VALUES
    (stud_sequence.CURRVAL,
    :NEW.App_User,
    'UPDATE',
    SYSDATE,
    'OLD VALUE',
    :OLD.stud_name,
    :OLD.stud_age,
    :OLD.stud_sex);
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    NULL;
    END Tgr_stud_det;
    Thanks in advance.

    Rizly,
    As i mentioned in the above post, you should remove the references of :old and :new when you are trying to use the global variables. These values are only significant when you the talk about the record in the table.
    For the scenario, you explained, your trigger would insert two records....The trigger would be fired twice.. once during the insert and once during the delete. The audit table will have two records indicating both the actions..
    Take a look at this example below...I am artificially manufacturing a user id in the package test_pkg and using that in the insert trigger. As i explained above, you dont need the :old and :new references because the user id is not a column in the table . hence the :old and :new references have no relevance.
    Also note that, for the delete, I use the :old value and for the insert, I use the :new value.
    for update, I assume you want to store the old record and hence used :old (you can of course use :new too..technically.).
    I don't have access to a forms environement, but the user id logic should be similar to what I described below.
    sql> create table t(
      2     id number,
      3     name varchar2(20)
      4  );
    Table created.
    sql> create table t_audit
      2     ( id number,
      3       name varchar2(20),
      4       action varchar2(20),
      5       user_id varchar2(20)
      6  );
    Table created.
    sql> create or replace package test_pkg as
      2      function get_user_id return varchar2;
      3  end test_pkg;
      4  /
    Package created.
    sql> create or replace package body test_pkg as
      2      function get_user_id return varchar2 is
      3      begin
      4          return 'USER' || to_char(sysdate,'HH24:MI');
      5      end get_user_id;
      6  end test_pkg;
      7  /
    Package body created.
      1  create or replace trigger trg_biud_t
      2     before insert or update or delete on t
      3     for each row
      4  begin
      5     if INSERTING then
      6        insert into t_audit values (:new.id, :new.name, 'INSERT',test_pkg.get_user_i
      7     elsif UPDATING then
      8        insert into t_audit values (:old.id, :old.name, 'UPDATE',test_pkg.get_user_i
      9     elsif DELETING then
    10        insert into t_audit values (:old.id, :old.name, 'DELETE',test_pkg.get_user_i
    11     end if;
    12* end;
    sql> /
    Trigger created.
    sql> select * from t;
    no rows selected
    sql> select * from t_audit;
    no rows selected
    sql> insert into t values (100, 'Rajesh');
    1 row created.
    sql> insert into t values (200,'Kumar');
    1 row created.
    sql> delete from t where id = 200;
    1 row deleted.
    sql> commit;
    Commit complete.
    sql> select * from t
      2  /
            ID NAME
           100 Rajesh
    sql> select * from t_audit;
            ID NAME                 ACTION               USER_ID
           100 Rajesh               INSERT               USER15:36
           200 Kumar                INSERT               USER15:36
           200 Kumar                DELETE               USER15:37

  • Instead of delete trigger rows deleted

    Hi All.
    Im using a few instead of triggers over a view. The view selects data from other tables and merges them together. This view essentially forms the parent of a few one2one relationships with other tables.
    However my application doesnt know its a view (im using hibernate orm framework) - so when I delete this object which is mapped to a view, I get an error saying that no records where deleted. Also, if i test in sqlplus, i get "0 rows deleted" in response to a delete - which of course is true, but i want it to say 1 or some number of my choice.
    How can i modify my "instead of delete" trigger so that the number for records deleted count returned to caller is 1, or some number i can define?
    Here is my current trigger...
    create or replace
    trigger product_view_delete_trigger
    instead of delete
    on product_view1
    for each row
    begin
    null;
    end;
    Thanks.

    In regards to why Im using a view - its discussed here...
    Crazy Union across 3 tables
    The view im using is not updatable - it uses a union. I use "instead of triggers" to trick my application into thinking its a real table which is insertable. And this works fine.
    Im having trouble tricking my application into think that the delete was successful, because the "instead of delete" trigger doesnt actually delete anything - which is what i wnat - but i want it to report back to the caller that a delete occurred.
    I want the SQL%ROWCOUNT to be set to 1 or whatever. Perhaps this is not hte variable, but im hoping there is some variable I can set which is used to report back to the client as to how many records were deleted.
    thx.

  • Selective use of a delete trigger

    Is there a way for me to use a delete trigger selectively?
    I have a table that on certain instances, when a record is deleted the 'deleted' record needs to be inserted into an archive table. On other times, the delete must just delete and no archive created.
    because I have a DELETE trigger, it is firing everytime a delete happens.
    Is there a way I can 'suspend' the trigger for those times?
    for example:
    DELETE /*+ No trg_del_price */ from PRICE where <where clause here>

    We have a price table that in some situations, multiple prices come in for the same account. We have an SP that does a clean-up routine and if it finds records that needs to be cleaned up, it updates those and then deletes the other records (as they are now duplcate). In these cases, I don't want the 'extra' records inserted into the archive table.
    (Note that this was not my code - but the original code written by a former DBA that has since left. It would be too complicated and time-consuming to rewrite the whole logic to not have this clean-up routine in the first place).
    If the record is truely deleted in all other cases, then I do want the record inserted. For that I call a trigger that calls a SP to do the insert.
    If I cannot do a selective trigger, can I put logic in the trigger that can check the source of the trigger - if from this clean-up SP, then don't fire....
    Sean

  • How to make before delete trigger

    Hi all
    I want make before delete trigger
    I have 2 tables hr_api_transactions and new_table
    when I delete records from hr_api_transations table
    then that deleted record should be stored/insert in new_table table
    for that purpose I need before delete trigger
    How can I make It?

    Hi
    I have written following code but it gives an error
    CREATE OR REPLACE TRIGGER before_delete_trigger
        BEFORE DELETE
            ON HR_API_TRANSACTIONS
            FOR EACH ROW
        DECLARE
        BEGIN
            delete from new_table where new_table.name = OLD.hr_api_transactions.api_addtnl_info;
        END;
    TRIGGER BEFORE_DELETE_TRIGGER compiled
    Errors: check compiler logafter show errors it shows
    4/54 PL/SQL: ORA-00904: "OLD"."HR_API_TRANSACTIONS"."API_ADDTNL_INFO": invalid identifier
    4/9 PL/SQL: SQL Statement ignoredhere hr_api_transaction is table which contain API_ADDTNL_INFO column
    and name column of new_table and API_ADDTNL_INFO column of
    HR_API_TRANSACTIONS table are same

  • PRE-DELETE TRIGGER ERROR

    I am debugging a program written by Developer/2000 forms 4.5
    I use 3 to 4 base tables and they all have parent/child relatioship.
    When i try to delete one of them , the error is : pre-delete trigger error.
    any idea ?

    Hi, Lesley
    Beware:
    your form_success test is not working.
    The form_success, form_failure and form_fatal functions should only be used to test the outcome of Forms Built-ins.
    If you want to test the result of DELETE statements, try:
    DELETE FROM TABLE
    WHERE CONDITION;
    IF SQL%FOUND THEN
    MESSAGE('Some rows were deleted');
    ELSE
    MESSAGE('No rows were deleted');
    END IF;You can also use SQL%ROWCOUNT to know how many rows were deleted.
    Hope this helps,

  • Help on delete trigger

    Hi all,
    I have a situation like this
    I have a table like
    SQL> desc system_user
    Name Null? Type
    ID NOT NULL NUMBER(12)
    USER_ID NOT NULL VARCHAR2(30)
    SQL> SELECT * FROM SYSTEM_USER
    2 ORDER BY CTUT_ID;
    CTUT_ID CURRENT_USER_ID
    1 KTYLOR
    2 EXAMPLE
    3 SCOTT
    SQL> DESC ALL_USERS;
    Name Null? Type
    USERNAME NOT NULL VARCHAR2(30)
    USER_ID NOT NULL NUMBER
    CREATED NOT NULL DATE
    What i need to do is i need to have before delete trigger to check the following condition when user try to delete a record in table
    SYSTEM_USER
    1) suppose user is trying to delete a record "SCOTT" IN TABLE
    SYSTEM_USER
    CONDITION SHOULD CHECK THAT IF USER_NAME EXITS IN TABLE "ALL_USER"
    1)IF HE EXITS THEN RAISE ERROR
    2)IF HE IS NOT EXITS THEN DELETE THE RECORD IN TABLE "SYSTEM_USER"
    SO I WROTE A CODE FOR TRIGGER
    SQL> CREATE OR REPLACE TRIGGER TIBD_USER
    2 BEFORE DELETE ON SYSTEM_USER FOR EACH ROW
    3 DECLARE
    4 FOUND_USER NUMBER(2);
    5 BEGIN
    6 SELECT COUNT(*) FROM ALL_USERS
    7 WHERE USERNAME = :OLD.USER_ID;
    8 IF FOUND_USER = 0 THEN
    9 DELETE FROM SYSTEM_USER
    10 WHERE ROWID := :NEW.ROWID;
    11 ELSE
    12 RAISE_APPLICATION_ERROR(-20000,'USER FOUND IN ALL_USERS TABLE');
    13 END IF;
    14 END TIBD_USER;
    15 /
    Warning: Trigger created with compilation errors.
    SQL> SHOW ERRORS
    Errors for TRIGGER TIBD_USER:
    LINE/COL ERROR
    7/1 PL/SQL: SQL Statement ignored
    8/13 PL/SQL: ORA-00920: invalid relational operator
    ANY HELP PLEASE

    1 CREATE OR REPLACE TRIGGER TIBD_USER
    2 BEFORE DELETE ON SYSTEM_USER FOR EACH ROW
    3 DECLARE
    4 FOUND_USER NUMBER(2);
    5 BEGIN
    6 SELECT COUNT(*) INTO FOUND_USER FROM ALL_USERS
    7 WHERE USERNAME = :OLD.USER_ID;
    8 IF FOUND_USER = 0 THEN
    9 DELETE FROM SYSTEM_USER
    10 WHERE ROWID = :OLD.ROWID;
    11 ELSE
    12 RAISE_APPLICATION_ERROR(-20000,'USER FOUND IN ALL_USERS TABLE');
    13 END IF;
    14* END TIBD_USER;
    SQL> /
    Trigger created.
    WHEN I DELETE A RECORD IT IS GIVING ME THAT
    SQL> DELETE FROM SYSTEM_USER
    2 WHERE CTUT_ID = 3;
    DELETE FROM SYSTEM_USER
    ERROR at line 1:
    ORA-04091: table SYSTEM_USER is mutating, trigger/function may not see it
    ORA-06512: at "TIBD_USER", line 7
    ORA-04088: error during execution of trigger 'TIBD_USER'

  • Delete trigger not working on delete button

    I have a form (parent) / report (children) combo page with all the default buttons (create, apply changes, delete, cancel) created from the wizard. I've created a before delete trigger on the parent table that basically finds all the children and deletes them. For debugging purposes, I've added some inserts into a test table to make sure my bind variables binding correctly (they are). When I confirm the java script delete and say ok, the insertion of the text for debugging purposes works fine, but the actual deletion of the other records does not. Any ideas why?

    Then it is easy-your delete process is not fireing!!
    Why...there may be many reasons....but I'm pretty sure that process is never fired!
    Look in your page or show us a demo on workspace

  • Before delete trigger and foreign key relationship

    Hi,
    I am analysing one database for migration. On one parent table there is before delete trigger , to delete records from child. Also there is foreign key relationship on child table for this parent table.
    When I am deleting a row from parent, message gets displayed as "there are child records found."
    I would like to know, if there is foreign key relatioship then delete trigger on parent does't work, what is exactly happening?

    Could you post that trigger code and the Oracle version as well?
    With basic assumptions, I can't reproduce what you have stated here.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> create table parent (id number primary key);
    Table created.
    SQL> create table child (id number);
    Table created.
    SQL> alter table child add constraint fk_parent foreign key (id) references parent;
    Table altered.
    SQL> create or replace trigger bdr_parent
      2  before delete on parent
      3  for each row
      4  begin
      5  delete from child where id = :old.id;
      6  end;
      7  /
    Trigger created.
    SQL> insert into parent (id) values (1);
    1 row created.
    SQL> insert into child (id) values (1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> delete from parent where id = 1;
    1 row deleted.
    SQL> select * from parent;
    no rows selected
    SQL> select * from child;
    no rows selected
    SQL> rollback;
    Rollback complete.
    SQL> alter table child drop constraint fk_parent;
    Table altered.
    SQL> alter table child add constraint fk_parent foreign key (id) references parent on delete cascade;
    Table altered.
    SQL> delete from parent where id = 1;
    delete from parent where id = 1
    ERROR at line 1:
    ORA-04091: table SCOTT.CHILD is mutating, trigger/function may not see it
    ORA-06512: at "SCOTT.BDR_PARENT", line 2
    ORA-04088: error during execution of trigger 'SCOTT.BDR_PARENT'
    SQL>

  • Retrieving old column values from a after delete trigger dynamically

    I have a single audit table for deletions
    and the table structure has the following columns
    1: table_name
    2: column_name
    3: column_value
    I am writing a trigger on tables for which i want to have delete audits and i am dynamicaly
    retrieving the column names but i am unable to retrieve the column value dynamically;
    I tried to use the following statement but doesn't return the column value
    sql_stmt:= 'select :1 from dual';
    execute immediate sql_stmt into col_value using
    ':old.'| |v_col_name;
    where v_col_name is the name of the column which i retrieve dynamically using the
    dbms_sql.describe_columns procedure.
    Is their any way if i can retrieve the old column values in the trigger dynamically if i already
    have the column names in variables..
    Thanks in advance.
    null

    I don't know if Kevin's tip Help Mr. Sameer, but it did help me gain access to pre-deleted row column values.
    I did discover, however, that if the columns from the about-to-be-deleted row are used as inserts into another table, Oracle serves up a nasty-gram informing the user that values from the about-to-be-deleted table are unreliable.
    I was able to circumvent this constraint by assigning the about-to-be-deleted column values to local PL/SQL varables, then perform the insert using the variable values.
    -Bill McNamee
    NHDOT
    [email protected]

  • Import of .bacpac fails on view with instead of delete trigger

    I'm using Azure Premium SQL. 
    When I export the database using the portal and blob storage and then immediately try to import it as a test to a new database (also using the portal) I get the error below.
    Looking at the restored database, many of the views are not there (including the one listed) although that may be because it failed on this view during the restore.
    The trigger seems to be working just fine in the original database.  It just won't restore from the bacpac.
    BTW, I notice in the original database before backup, the trigger says "DELETE
    FROM alndata.AptChangeLog", not "DELETE alndata.AptChangeLog"
    Thanks.
    Bryan
    Error encountered during the service operation. 
     Could not import package.
     Error SQL72014: .Net SqlClient Data Provider: Msg 8197, Level 16, State 4, Procedure AdminChangeLogAptNameDelete, Line 7 The object 'AlnData.AdminChangeLogAptName' does not exist or is invalid for this operation.
     Error SQL72045: Script execution error. The executed script:
     CREATE TRIGGER [AlnData].[AdminChangeLogAptNameDelete]
     ON [AlnData].[AdminChangeLogAptName]
     INSTEAD OF DELETE
     AS BEGIN
     SET NOCOUNT ON;
     DELETE alndata.AptChangeLog
     WHERE aptchangelog_id IN (SELECT aptchangelog_id FROM deleted);
     END

    Hello,
    Sorry for delay.
    I had found a feedback about trigger issue when restore SQL Database from a BACPAC file. Microsoft said the fixed  will be available in the next major release of DacFx.
    Feedback:
    SQL Azure fires a trigger when restoring from bacpac
    You can refer to the workarounds in the feedback. For example, if there is small amount of triggers on the database, you can try to remove the triggers and then recreate when restore from bacpac file.
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Insert, update and delete trigger over multiple Database Links

    Hello guys,
    first of all I'll explain my environment.
    I've got a Master DB and n Slave Databases. Insert, update and delete is only possible on the master DB (in my opinion this was the best way to avoid Data-inconsistencies due to locking problems) and should be passed to slave databases with a trigger. All Slave Databases are attached with DBLinks. And, additional to this things, I'd like to create a job that merges the Master DB into all Slave DB's every x minutes to restore consistency if any Error (eg Network crash) occurs.
    What I want to do now, is to iterate over all DB-Links in my trigger, and issue the insert/update/delete for all attached databases.
    This is possible with the command "execute immediate", but requires me to create textual strings with textually coded field values for the above mentioned commands.
    What I would like to know now, is, if there are any better ways to provide these functions. Important to me is, that all DB-Links are read dynamically from a table and that I don't have to do unnecessary string generations, and maybe affect the performance.
    I'm thankful for every Idea.
    Thank you in advance,
    best regards
    Christoph

    Well, I've been using mysql for a long time, yes, but I thought that this approach would be the best for my requirements.
    Materialized View's don't work for me, because I need real-time updates of the Slaves.
    So, sorry for asking that general, but what would be the best technology for the following problem:
    I've got n globally spread Systems. Each of it can update records in the Database. The easies way would be to provide one central DB, but that doesn't work for me, because when the WAN Connection fails, the System isn't available any longer. So I need to provide core information locally at every System (connected via LAN).
    Very important to me is, that Data remain consistent. That means, that it must not be that 2 systems update the same record on 2 different databases at the same time.
    I hope you understand what I'd need.
    Thank you very much for all your replies.
    best regards
    Christoph
    PS: I forgot to mention that the Databases won't be very large, just about 20k records, and about 10 queriees per second during peak times and there's just the need to sync 1 Table.
    Edited by: 907142 on 10.01.2012 23:14

  • Before delete trigger?

    We are trying to determine who (like in what applicaton) is deleting rows in one table that leaves "orphaned" rows in another.
    We create the following trigger...
    create or replace Trigger EFA_TRG_AUDIT
    before delete on EFA_EXTERNAL_FILE_ATTACHMENT
    for each row
    declare
    OS_USER varchar2 (20);
    HOST varchar2 (20);
    MODULE varchar2 (48);
    SESSION_USER varchar2 (20);
    Begin
    if :old.EFA_LDS_UID is not null then
    SELECT substr(SYS_CONTEXT ('USERENV', 'SESSION_USER'),1,20) into SESSION_USER from dual;
         SELECT module into MODULE from v$session where audsid=userenv('SESSIONID');
         SELECT substr(SYS_CONTEXT ('USERENV', 'HOST'),1,20) into HOST from dual;
         SELECT substr(SYS_CONTEXT ('USERENV', 'OS_USER'),1,20) into OS_USER from dual;
    insert into EFAA_EFA_AUDIT values(
         :old.EFA_UID,
         :old.EFA_SYT_CODE_PARENT,
         :old.EFA_PARENT_KEY,
         :old.EFA_SEQUENCE,
         :old.EFA_FILENAME,
         :old.EFA_DESC,
         :old.EFA_LDS_UID,
         :old.EFA_CREATE_DATE,
         :old.EFA_USR_UID_CREATED_BY,
         :old.EFA_LAST_UPDATE_DATE,
         :old.EFA_USR_UID_UPDATED_BY,
         :old.EFA_FAT_CODE,
         :old.EFA_FILE_SIZE,
         'DELETE',
    HOST,
    OS_USER,
         MODULE,
    User,
         Sysdate);
    end if;
    end;
    This will create an "audit table" which works fine but includes ALL deletes including valid deletes that leave no "orphans" (EFA_LDS_UID).
    The LDS table can have rows that are not related to the EFA so a constraint cannot be used.
    Any ideas?

    no need to clean up the data. just create the FK as NOVALIDATE
    from the SQL Reference manual:
    ENABLE NOVALIDATE ensures that all new DML operations on the constrained data comply with the constraint. This clause does not ensure that existing data in the table complies with the constraint and therefore does not require a table lock

  • Passsing value to Before Delete Trigger

    I've never seen this done and wanted to see if it's even possible.
    They have created an application using access to fill out a form that a user is signed into. Once the form is created they submit the data to Oracle calling a process as a generic user. They want to be able to capture the user that was logged into Access to update when the trigger is fired and audit record created.
    I'm fairly new to what they are doing here and I think the easiest is just to create a procedure to update the audit table and delete the record, and forget about trying to use a trigger for this purpose.
    Any thoughts out there that might have more experience in this area.
    Thanks

    ...and when that package state is discarded by a patch release the sumbit button on the access form will stop working randomly, and the users will be figure out that they need to click the button twice sometimes and just to be safe always, and you'll end up with loads of duplicated audit entries.
    ...and when someone deletes by logging in as the "generic user" direct from an Access query, or ODBC or SQL*Plus or some random other tool, you'll have no idea who did it.
    The generic user idea is a bad one.

Maybe you are looking for

  • Settlement rule for AUC

    Dear SAP gurus, In AIAB, I have assigned the settlement rule for AUC asset id. However I am not able to see the settlement rule assigned in  As03. Is there any report

  • Upgrade to 9.2.0.8

    Hi everyone, I have an oracle 9.2.0.1 running on AIX 5.3 ML 4 64-bit. I am trying to upgrade it to 9.2.0.8. Does anyone have a tested approach to this? Some kind of problem? Thanks.

  • Jax-rpc and xsd x:any/

    I am using JAX-RPC to build a client for a web service. Some of the operations on the web service include an <x:any/> element in the response. JAX-RPC generates a corresponding javax.xml.soap.SOAPElement for each of the elements defined as <x:any/>.

  • Slow printing from windows 2008 R2 with Cisco 6509

    Dear All, I am having a wiered issue in my network. We have a windows 2008 R2 print server. Normal documents print's fine. If you print a image or pdf file, it takes a long time to print. For example a 2 MB PDF image with two page took me 10 minutes

  • Config port channel across different type of media

    Please help with the question if we could config port channel across different media type such as Gigabit and Ethernet 10/100 ports ? thanks in advance.