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)< 5 then
10 raise e_tooShort;
11 elsif length(i_zipCode)> 6 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>
|