| Exception query [message #573396] |
Thu, 27 December 2012 19:11  |
 |
Bagheera
Messages: 2 Registered: December 2012
|
Junior Member |
|
|
Hi,
I'm a newbie to PL/SQL. I had a quick query about trapping exceptions.
I have a sample table called my_emp, which contains last name, salary, etc. I have written the following code that takes in an employee salary and if the salary exists it displays the last name and corresponding salary. If two or more rows are returned, the exception handles it. Likewise if there are no records with that salary, the exception takes care of it.
I was trying to input an alphanumeric input, such as 1bbb as the salary and of course ORA-06502 error pops up in the sql command line. I now want to trap this using an exception but whatever I try I still get the ORA-06502 in the calling environment rather than getting the 'Not a number' or 'Some other error occured' message. Any reason why the WHEN VALUE_ERROR or the WHEN OTHERS exceptions are not trapping the error?
Thanks so much.
Birdy
DECLARE
v_sal NUMBER (12) := '&Enter_salary';
v_last_name VARCHAR2(10);
BEGIN
SELECT last_name
INTO v_last_name
FROM my_emp
WHERE salary=v_sal;
DBMS_OUTPUT.PUT_LINE('Name: ' || v_last_name || ' Salary: ' || v_sal);
EXCEPTION
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('More than one employee with salary of ' || v_sal);
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No employees with salary of ' || v_sal);
WHEN VALUE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('Not a number');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Some other error occured');
END;
[Updated on: Thu, 27 December 2012 19:31] Report message to a moderator
|
|
|
|
|
|
|
|
|
|