vaibhav
vaibhav

Reputation: 644

disable update of row in oracle

I am using spring-boot and oracle. I am processing data over kafka and a single row is update asynchronously many time updating the count over different topic listeners.

Now i want to terminate this process. Since multiple threads will be updating it. There can be chance that the status is update during this processing part. Can i handle this thing from database itself saying if a particular column's value (say status) is "TERMINATED" it should reject all the updates on this row.

Upvotes: 0

Views: 509

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65228

You can create a database trigger during the update dml operation where upcoming value for status column should be prevented if the new column value is TERMINATED :

CREATE OR REPLACE TRIGGER Trg_Upd_Disable
BEFORE UPDATE ON tab
FOR EACH ROW
BEGIN
  IF :OLD.status = 'TERMINATED' THEN
    RAISE_APPLICATION_ERROR(-20202, 'The Process cannot be terminated !!');
  END IF;  
END;
/

Demo

Upvotes: 2

Related Questions