Reputation: 37
I want to catch the specific exception thrown when sequence.nextval
reaches MAXVALUE in Oracle?
I don't want to use EXCEPTION WHEN OTHERS; I want to catch the specific exception for my logger.
Upvotes: 1
Views: 1367
Reputation: 27251
You can declare a user defined exception and associate the exception code -8004
(the code of exception that is raised when a sequence exceeds its maximum value) with it using pragma exception_init()
and then catch that specific exception. Here is an example:
SQL> declare
2 l_ex_max_val exception;
3 pragma exception_init(l_ex_max_val, -8004);
4 l_val number;
5 begin
6 l_val := gen_val.nextval; -- This kind of assignment is allowed
7 exception -- in 11g and further versions. In earlier versions
8 when l_ex_max_val -- you would use select statement
9 then dbms_output.put_line('ERROR! sequence gen_val exceeds its max value');
10 end;
11 /
ERROR! sequence gen_val exceeds its max value
PL/SQL procedure successfully completed
SQL>
Upvotes: 4