Total Pageviews

May 20, 2015

5/20/2015 11:48:00 PM
Exceptions
Two types of Exceptions
1 ) Named System Exceptions
2) Names Programmer Exception
Oracle Exception Name Oracle Error Explanation
DUP_VAL_ON_INDEX ORA-00001 You tried to execute an INSERT or UPDATE statement that has created a duplicate value in a field restricted by a unique index.
TIMEOUT_ON_RESOURCE ORA-00051 You were waiting for a resource and you timed out.
TRANSACTION_BACKED_OUT ORA-00061 The remote portion of a transaction has rolled back.
INVALID_CURSOR ORA-01001 You tried to reference a cursor that does not yet exist. This may have happened because you've executed a FETCH cursor or CLOSE cursor before OPENing the cursor.
NOT_LOGGED_ON ORA-01012 You tried to execute a call to Oracle before logging in.
LOGIN_DENIED ORA-01017 You tried to log into Oracle with an invalid username/password combination.
NO_DATA_FOUND ORA-01403 You tried one of the following:
 You executed a SELECT INTO statement and no rows were returned.
 You referenced an uninitialized row in a table.    You read past the end of file with the
TOO_MANY_ROWS ORA-01422 You tried to execute a SELECT INTO statement and more than one row was returned.
ZERO_DIVIDE ORA-01476 You tried to divide a number by zero.
INVALID_NUMBER ORA-01722 You tried to execute a SQL statement that tried to convert a string to a number, but it was unsuccessful.
STORAGE_ERROR ORA-06500 You ran out of memory or memory was corrupted.
PROGRAM_ERROR ORA-06501 This is a generic "Contact Oracle support" message because an internal problem was encountered.
VALUE_ERROR ORA-06502 You tried to perform an operation and there was a error on a conversion, truncation, or invalid constraining of numeric or character data.
CURSOR_ALREADY_OPEN ORA-06511 You tried to open a cursor that is already open.
Syntax:
CREATE [OR REPLACE] PROCEDURE xxemp_validate
   (p_empno Number)
IS
l_empno  number;
   BEGIN
   select empno into l_empno from emp
      where empno=p_empno;
EXCEPTION
   WHEN no_data_found  THEN
      dbms_output.put_line('No Matching records found');
   WHEN  too_many_rows THEN
       dbms_output.put_line('Too many records found');
   WHEN  others THEN
      dbms_output.put_line('Other Errors);
  END [procedure_name];
Names Programmer Exception
What is a named programmer-defined exception in Oracle?
Sometimes, it is necessary for programmers to name and trap their own exceptions - ones that aren't defined already by PL/SQL. These are called Named Programmer-Defined Exceptions.
CREATE [OR REPLACE] PROCEDURE procedure_name
   [ (parameter [,parameter]) ]
IS
   [declaration_section]
   exception_name EXCEPTION;
BEGIN
   executable_section
   RAISE exception_name;
EXCEPTION
   WHEN exception_name THEN
      [statements]
         WHEN OTHERS THEN
      [statements]
END [procedure_name];

ex:
CREATE OR REPLACE PROCEDURE add_new_job
   (p_job varchar)
IS
   no_job EXCEPTION;
BEGIN
   IF p_jobs is nullTHEN
      RAISE no_job;

   ELSE
      INSERT INTO job (job_id, job_name )
      VALUES ( job_id,p_job );
   END IF;

EXCEPTION
   WHEN no_job THEN
      raise_application_error (-20001,'No job');

   WHEN OTHERS THEN
      raise_application_error (-20002,'An error has occurred inserting an order.');

END;
 
Related Posts Plugin for WordPress, Blogger...