Handle errors in Oracle functions, processes, triggers, and so on

Source: Internet
Author: User

I. Caught error exceptions

1: capture predefined error exceptions in the Oralce system.

2: capture custom error exceptions.

Ii. Methods for capturing error exceptions

In the Oralce database object.

1: Definition error variable

User_Exception EXCEPTION;

2:Begin

-- Execute SQL statements

Exception

When others then
Null;

End;

Instance:

Create or replace procedure P_User_Pro (AL_ORDER_ID in NUMBER) is

Order_Id_Null EXCEPTION; -- custom error EXCEPTION

If AL_ORDER_ID = 0 or isnull (AL_ORDER_ID) then

RAISE Order_Id_Null;

End if;

Begin

Update User_Table_Name

Set order_state = '01'

Where order_id = AL_ORDER_ID;

Exception

When others then
RAISE_APPLICATION_ERROR (-20014, 'an error occurred while updating the document status! Error: '| SQLCODE | SQLERRM );
Return;

End;

Exception

When Order_Id_Null then -- catch custom error exceptions

RAISE_APPLICATION_ERROR (-20015, 'incorrect document ID! Error: '| SQLCODE | SQLERRM );

Rollback;

When other then

RAISE_APPLICATION_ERROR (-20016, 'an error occurred while updating the document status! Error: '| SQLCODE | SQLERRM );

Rollback;

End P_User_Pro;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.