Raise Exception in a function : Raise Exception : PL SQL Programming : Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. Object Oriented
32. XML
33. Large Objects
34. Transaction
35. User Privilege
Java
Java Tutorial
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Oracle PL/SQL Tutorial » PL SQL Programming » Raise Exception 
24. 14. 2. Raise Exception in a function

SQL> set serveroutput on
SQL> DECLARE
  2       quantity1 NUMBER := -2;
  3       quantity2 NUMBER := 3;
  4       total NUMBER := 0;
  5       quantity_must_positive EXCEPTION;
  6       FUNCTION find_cost (quant NUMBERRETURN NUMBER IS
  7       BEGIN
  8            IF (quant > 0)
  9            THEN
 10                 RETURN(quant * 20);
 11            ELSE
 12                 RAISE quantity_must_positive;
 13            END IF;
 14       END find_cost;
 15  BEGIN
 16       total := find_cost (quantity2);
 17       total := total + find_cost(quantity1);
 18  EXCEPTION
 19       WHEN quantity_must_positive
 20       THEN
 21            dbms_output.put_line('Total until now: ' || total);
 22            dbms_output.put_line('Tried to use negative quantity ');
 23  END;
 24  /
Total until now: 60
Tried to use negative quantity

PL/SQL procedure successfully completed.

SQL>
SQL>

        
24. 14. Raise Exception
24. 14. 1. User-Defined Errors
24. 14. 2. Raise Exception in a function
24. 14. 3. Raising an Exception Local PL/SQL Block
24. 14. 4. Avoiding exceptions raised in declaration part and exception handler
24. 14. 5. Raising an Exception in the Declaration Section
24. 14. 6. Exceptions Raised in the Exception Handler
24. 14. 7. Raising NO_DATA_FOUND
24. 14. 8. Raising a custom exception
Home | Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.