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 to stop log file growing too big?

569


What are the properties of primary key?

502


On a windows server 2003 active – passive failover cluster, how do you find the node which is active?

640


What is a join in sql? What are the types of joins?

515


How do you trace the traffic hitting a sql server?

612






Define indexes?

601


Explain forward - only cursors?

511


How would you choose between a clustered and a non-clustered index?

537


How to get the query of a table in sql server?

494


Does windows server 2016 come with sql server?

497


Explain Normalization and DE normalization

600


List some case manipulation functions in sql?

587


How many database files are there in sql server 2000?what are they?

572


You are creating an application where users are asked their gender in the gender combo box you have three options: ‘male’ , ‘female’ and ‘i choose not to disclose’ these options are stored in the table as 1, 0 or null which datatype should you use?

539


How to create a user name in a database?

580