Raising an Exception in the Declaration Section : 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. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » PL SQL Programming » Raise Exception 
24. 16. 5. Raising an Exception in the Declaration Section
SQL> create or replace procedure p_validatezip (i_zipCode VARCHAR2)
  2  is
  3       e_tooShort EXCEPTION;
  4       e_tooLong  EXCEPTION;
  5       e_badZip   EXCEPTION;
  6       pragma exception_init(e_badZip, -20998);
  7       v_tempZip number:=to_number(i_zipCode);
  8  begin
  9       if length(i_zipCode)then
 10         raise e_tooShort;
 11       elsif  length(i_zipCode)then
 12         raise e_tooLong;
 13       end if;
 14  exception
 15       when e_tooLong then
 16          DBMS_OUTPUT.put_line('long zip');
 17          raise e_badZip;
 18       when e_tooShort then
 19          DBMS_OUTPUT.put_line('short zip');
 20       when VALUE_ERROR then
 21          DBMS_OUTPUT.put_line('non-numeric zip');
 22          raise e_badZip;
 23    end;
 24  /

Procedure created.

SQL>
SQL> declare
  2
  3  begin
  4      p_validatezip('9123412341234');
  5  end;
  6  /
long zip
declare
*
ERROR at line 1:
ORA-20998:
ORA-06512: at "JAVA2S.P_VALIDATEZIP", line 17
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at line 4


SQL>
24. 16. Raise Exception
24. 16. 1. User-Defined Errors
24. 16. 2. Raise Exception in a function
24. 16. 3. Raising an Exception Local PL/SQL Block
24. 16. 4. Avoiding exceptions raised in declaration part and exception handler
24. 16. 5. Raising an Exception in the Declaration Section
24. 16. 6. Exceptions Raised in the Exception Handler
24. 16. 7. Raising NO_DATA_FOUND
24. 16. 8. Raising a custom exception
24. 16. 9. Using WHEN OTHERS clause
24. 16. 10. Using SQLCODE and SQLERRM
24. 16. 11. Propogating a Server-side Customized Error Number and Error Message to client program using PRAGMA EXCEPTION_INIT
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.