I have a long list of UPDATE
statements that I run on my Oracle 11g server:
UPDATE Table SET Column1 = 'One' WHERE Column2 = 'Example';
UPDATE Table SET Column1 = 'Two' WHERE Column2 = 'Something';
-- ...
I want to check that each UPDATE
affects exactly one row (not zero, not more than one), and if it doesn't stop the execution, raise an error, and roll back all of the updates.
I was hoping for a syntax like this perhaps:
UPDATE Table SET Column1 = 'One' WHERE Column2 = 'Example';
ASSERT sql%rowcount = 1;
That does not seem to exist, so maybe I should do something like this:
UPDATE Table SET Column1 = 'One' WHERE Column2 = 'Example';
IF sql%rowcount != 1 THEN
-- Do something, but what?
END IF;
However, I am not sure what to put inside the IF
statement or if that is even a good approach. So, what is the most elegant way of accomplishing this?