I have some procedure written in Oracle. Unfortunately I can't show its code. Somewhere inside it is select where execution crashed because of absence of required data. It looks like this
select value into l_value
from config
where code = upper(p_code);
So when I call this procedure like this (in SqlDeveloper)
execute some_package.some_procedure('CODE');
it throws
Error report -
ORA-01403: no data found
ORA-06512: at "XXXXXXXXXXXXXXXXXXX", line 111
ORA-06512: at "XXXXXXXXXXXXXXXXXXX", line 111
ORA-06512: at line 1
01403. 00000 - "no data found"
*Cause: No data was found from the objects.
*Action: There was no data from the objects which may be due to end of fetch.
But when I call it like this
call some_package.some_procedure('CODE');
it crashes at the same place (as I can suggest from the result, stored in DB), but it does no throw an exception.
some_package.some_procedure('CODE') succeeded.
What happens? And why there is such difference?
Oracle uses two built in functions for catching exceptions and getting its information, SQLCODE and SQLERRM. SQLCODE: It returns the error number for the last encountered error. SQLERRM: It returns the actual error message of the last encountered error.
There are three types of exceptions: Predefined exceptions are error conditions that are defined by PL/SQL. Non-predefined exceptions include any standard TimesTen errors. User-defined exceptions are exceptions specific to your application.
Retrieving the Error Code and Error Message: SQLCODE and SQLERRM. In an exception handler, you can use the built-in functions SQLCODE and SQLERRM to find out which error occurred and to get the associated error message. For internal exceptions, SQLCODE returns the number of the Oracle error.
Now With SAVE EXCEPTIONS COUNT SAVE EXCEPTIONS UPDATE employees SET first_name = enames_with_errors (indx); ROLLBACK; EXCEPTION WHEN std_errs. failure_in_forall THEN DBMS_OUTPUT. put_line (SQLERRM); DBMS_OUTPUT.
NO_DATA_FOUND
exception behavior is special. It is handled by default in SQL context but not in PL/SQL. In SQL no data found is not considered as an error, it happens all the time that there is no data that meets certain condition.
CALL
is SQL command whereas EXEC
is a shortcut for BEGIN <code> END;
which is PL/SQL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With