How to handle errors in Stored Procedures.

Answer Posted / saraswathi muthuraman

If the procedure execution fails the oracle will quit the
execution with an error.

This error can be handled with in store procedure using
"exception".

declare
test_excep_name exception;
x number;
Begin
select emp_no into x from emp_test where emp_no=1;
If SQL%NOTFOUND then
raise test_excep_name;
end if;

exception
when test_excep_name then
dbms_output.put_line(' Error occurred during execution' || '
SQL error code is ' || sqlcode || ' SQL error maessage '||
sqlerrm);
when others then
dbms_output.put_line(' Error occurred during execution- This
is unknown error ' || ' SQL error code is ' || sqlcode || '
SQL error maessage '|| sqlerrm);
end;
/

Result :

Error occurred during execution- This is unknown error SQL
error code is 100
SQL error maessage ORA-01403: no data found

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does using a separate hard drive for several database objects improves performance right away?

533


How to populate a table in sql server?

507


What is Cross Join and in which scenario do we use Cross Join?

576


What is conditional split?

543


how to control the amount of free space in your index pages? : Sql server database administration

602






How do I view a trc file?

507


What do you understand by recursive stored procedures?

572


Can we delete data from a view?

545


What are commit and rollback in sql?

571


What is unpivot?

576


Explain the difference between control flow and data flow?

532


What happens if an integer is too big for int date type?

581


Explain indexes disadvantages?

555


Which feature in sql server 2008 has surprised you? You can name just one. : sql server database administration

503


How to drop an existing user defined function in ms sql server?

571