Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferent timestamp for different DML queries in single transaction in oracle
    primarykey
    data
    text
    <p>I am doing an insert and delete operation on a table in single transaction.I have trigger on this table which update the log.The log has primary key as sequenceId which always gets incremented on insertion.I do delete first and then insert in the transaction.</p> <p>I have two issues :</p> <ul> <li>The timestamp in the log for the insert and delete is being same. Can I force it to be different.</li> <li>The order of operation(insert/delete) in the log is getting reversed. It shows delete operation coming after insert operation(according to sequenceId).How can I ensure that the order is consistent in the log(insert after delete).</li> </ul> <p>Example :</p> <pre><code>create table address (ID number, COUNTRY char(2)); create table address_log(SEQ_ID number, ID number, COUNTRY char(2), DML_TYPE char(1), CHANGE_DATE timestamp(6)); create sequence seq_id start with 1 increment by 100 nominvalue nomaxvalue cache 20 noorder; create or replace trigger trg_add before insert or delete on address FOR EACH ROW BEGIN if inserting then insert into address_log values(SEQ_ID.nextval, :new.ID, :new.COUNTRY, 'I', sysdate); else insert into address_log values(SEQ_ID.nextval, :old.ID, :old.COUNTRY, 'D', sysdate); end if; end; insert into address values(1,'US'); insert into address values(2,'CA'); delete from address where id = 1; insert into address values(3,'UK'); delete from address where id = 3; </code></pre> <p>if I commit last DML queries in single transaction, then I should see the same order in address_log.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload