how to capture the error when RID value not in the table (pl/sql question)

From: Guang Mei <GMei@xxxxxx>

To: "Oracle-L (E-mail)" <Oracle-L@xxxxxxxxxxxxx>

Date: Wed, 23 Feb 2005 13:22:57 -0500

I have the following code in a pl/sql procedure (oracle 9i), which is called
a lot.
-- RID is PK column on table Customers
-- p_name is a passed-in parameter
-- p_CustomerRID is a passed-in parameter
SAVEPOINT sp123;
UPDATE Customers
SET Name = p_name
WHERE RID = p_CustomerRID;
IF SQL%ROWCOUNT > 1 THEN
ROLLBACK WORK TO SAVEPOINT sp123;
RaiseError.TooManyUpdates('Customers');
ELSIF SQL%ROWCOUNT = 0 THEN
RaiseError.NoRecordUpdated('Customers');
END IF;
The code works fine now. But I would to change the update sql to
UPDATE Customers
SET Name = p_name
WHERE RID = p_CustomerRID
AND Name != p_name;
to avoid unnecessary redo writing. But if I check SQL%ROWCOUNT for this new
query and get 0, I would not know if it is due to a non-exist RID (Which I
want to capture this situation) or simply p_name already exists for that
RID. Is there a better way of doing this kind of thing, minimize redo
writing and capture the error the same time with only one sql run?
TIA.
Guang
*************************************************************************
PRIVILEGED AND CONFIDENTIAL:
This communication, including attachments, is for the exclusive use of
addressee and may contain proprietary, confidential and/or privileged
information. If you are not the intended recipient, any use, copying,
disclosure, dissemination or distribution is strictly prohibited. If you
are not the intended recipient, please notify the sender immediately by
return e-mail, delete this communication and destroy all copies.
*************************************************************************
--
http://www.freelists.org/webpage/oracle-l