PL/SQL Oracle Error Handling -
I created a trigger that gives 10 existing orders to only one user, so now when the customer moves the order number 11 , Oracle database throws an error back. Well 3 Errors
ORA-20000: You currently have 10 or more order processing.
ORA-04088: error during execution of trigger 'C3283535.TRG_ORDER_LIMIT'
ORA-06512: "C3283535.TRG_ORDER_LIMIT"
The top error is one I have used:
raise_application_error (-20000), 'you currently have 10 or more order processing.');
I was just thinking after searching and was trying to change error messages for other two errors or show them in many ways for the user all together?
Here is the code I used
Before entering the placed_order for each row, declare the v_count number to trigger or change trg_order_limit; Start - get calculation count (order_ID) of the current order count placed in v_count / command where fk1_customer_id =: new.fk1_customer_id; - Increase exception if there are too many if v_count & gt; = 10 exceptions while other raise_application_error (-20000, 'you currently have 10 or more order processing.'); end if; End;
Many thanks Richard
Exception spread-to-external Block, which is the opposite of the variable scope, which comes out from the inner block of the interior. For more context about this, read McLoughlin's "Programming with PL / SQL", Chapter 5.
An exception stack is what you are doing here - the exceptions raised from the inner block for outermost blocks. >
When you raise an exception with a trigger, your
raise_application_error statement returns a error.
Then it is promoted for the trigger block which says
ORA-06512: "C3283535.TRG_ORDER_LIMIT", line 12 . This is because the trigger prevents an exception raised as an error and continues to continue.
The error is then propagated to the session which is 'code' ORA-04088: error 'C3283535 TRG_ORDER_LIMIT' during execution of the trigger. This error tells us about, as part of the program, the error was raised.
If you are using front-end programs like Java Server Pages or PHP, then you will catch the error raised - 20000 First, you can also display it to your end user. Edit > Can change in statement only.
If you want to handle
ORA-06512 , then you can use Uday Shankar's answer to take care of this error and help show a suitable error message. .
But, you can still get the last
ORA-04088 . If I was in your place, I would not be worried, after getting the
ORA-20000 , I extend an application error on the front side while hiding all the other details from the user.
In fact, this is is the nature of the exception stack of Oracle. All the errors from inner side to the outermost block have been raised. This is useful sometimes for us to identify the exact source of error.
Comments
Post a Comment