Learn to add Exceptions to PL/SQL block
- Review the code so far. Notice all the variables that have been declared. Next, declare
sale_price_exception
.
- 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
.
- Review the code so far. At this point, you need to start the exception handler section.
- Next, begin to handle the exception if there is no product in the database with the product ID supplied by the end user.
- 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.
- Next, begin to handle the sales price exception.
- 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.
- Next, begin to handle exceptions for all other database errors that you need to trap.
- Capture the SQL code to the
v_error_code
variable.
- Capture the SQL error message to the
v_error_message
variable.
- Display the SQL code in the format 'SQLcode: <database_code>' .
- Display the SQL error message in the format 'SQL error message: <database_error_message>' .
- End the block.
- Execute your block.
- SQL*Plus now displays the result of the compilation of your block.