Home » SQL & PL/SQL » SQL & PL/SQL » Exception Handling for Update
Exception Handling for Update [message #7219] Wed, 28 May 2003 09:20 Go to next message
RB
Messages: 11
Registered: April 2002
Junior Member
I have written a function that update a table in the database. I wanted to know some specific exception handling that I can do for the Update statement.

Thanks
RB
Re: Exception Handling for Update [message #7220 is a reply to message #7219] Wed, 28 May 2003 12:01 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
You'll have to be more specific - what exceptions do you want to handle? No rows updated, unique constraint violated, etc.? There are many exceptions that could be raised.
Re: Exception Handling for Update [message #7221 is a reply to message #7220] Wed, 28 May 2003 12:03 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
And the failure to update a row isn't even an exception, but it could be tested for using sql%rowcount. So, more details would be helpful.
Re: Exception Handling for Update [message #7222 is a reply to message #7221] Wed, 28 May 2003 12:24 Go to previous messageGo to next message
RB
Messages: 11
Registered: April 2002
Junior Member
If the row is not updated , its ok i dont want to raise it as an exception. but if an update statement fails (due to whatever reason) i want to handle that. Hope i am clear now !
Re: Exception Handling for Update [message #7223 is a reply to message #7222] Wed, 28 May 2003 12:55 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
By "handle" it, do you mean raise a generic error message?

create or replace function ...
is
begin
  update ...;
exception
  when others then
    raise_application_error(-20000, 'Error in update');
end;
Re: Exception Handling for Update [message #7224 is a reply to message #7223] Wed, 28 May 2003 13:20 Go to previous messageGo to next message
RB
Messages: 11
Registered: April 2002
Junior Member
Thanks Ted, I guess i could not explain what I want. I do have a 'WHEN OTHERS' part in exception handling. I just wanted to handle any Update specific exception which makes the Update statement fail! Is this possible at all ?
Re: Exception Handling for Update [message #7225 is a reply to message #7224] Wed, 28 May 2003 13:25 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Ted? How about Todd?

This is the type of thread that develops when the original post is very generic and has no code sample at all.

My earlier statement still applies - there are numerous exceptions that could be raised as the result of an update. As with any exception handling, if you want to handle them specifically, you have to list each one you care about.
Re: Exception Handling for Update [message #7226 is a reply to message #7225] Wed, 28 May 2003 13:44 Go to previous messageGo to next message
RB
Messages: 11
Registered: April 2002
Junior Member
Am Sorry about the name Todd.

I got what u r saying. I will give an example code and can you tell me if I can add any update specific exception to it ??

declare
cursor c1 is select * from employee
where emp_id <100
for update of desc;
c1_rec c1%ROWTYPE

begin
for c1_rec IN c1
loop
update employee
set desc = 'One of first hundred employees'
where current of c1;
end loop;

exception
when no_data_found then
dbms_output.put_line('no data found ');
when others then
dbms_output.put_line(' others ');
end;

Thanks a lot!
Re: Exception Handling for Update [message #7227 is a reply to message #7226] Wed, 28 May 2003 16:11 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Again, there is a long laundry list of possible exceptions. NO_DATA_FOUND will not be one of them - that is only raised on a SELECT INTO statement.

Some exceptions that come to mind (and these are not all pre-defined):

[*]inserted value too large for column
[*]cannot update to null
[*]conversion errors
[*]parent/child (RI) errors
[*]exceptions raised through triggers (validation code)

Maybe if you explain why you want to trap for exceptions (what are you going to do with them after you've trapped them) we could better help with an approach.
Previous Topic: Oracle Wrap Utility changed runtime source
Next Topic: Assigning Tablespace....
Goto Forum:
  


Current Time: Tue Apr 23 19:27:26 CDT 2024