PL/SQL Exceptions  «Prev 

Learn to add Exceptions to PL/SQL block

  1. Review the code so far. Notice all the variables that have been declared. Next, declare sale_price_exception.
  2. Review the code so far. At this point, you are checking to see that the sale price is less than or equal to zero. If it is, raise sale_price_exception.
  3. Review the code so far. At this point, you need to start the exception handler section.
  4. Next, begin to handle the exception if there is no product in the database with the product ID supplied by the end user.
  5. Next, handle the NO_DATA_FOUND exception. Display 'Error: Product ID does not exist' on the screen using the DBMS_OUTPUT.PUT_LINE package procedure.
  6. Next, begin to handle the sales price exception.
  7. Next, handle the sale_price_exception exception. Display 'Error: Sale Price in the database is incorrect.' on the screen using the DBMS_OUTPUT.PUT_LINE package procedure.
  8. Next, begin to handle exceptions for all other database errors that you need to trap.
  9. Capture the SQL code to the v_error_code variable.
  10. Capture the SQL error message to the v_error_message variable.
  11. Display the SQL code in the format 'SQLcode: <database_code>' .
  12. Display the SQL error message in the format 'SQL error message: <database_error_message>' .
  13. End the block.
  14. Execute your block.
  15. SQL*Plus now displays the result of the compilation of your block.