A function that uses Oracle Exception Handling

Source: Internet
Author: User

The main body of Oracle functions is as follows:

Create or replace function fn_get_agmt_bal (p_agmt_no varchar2)
RETURN NUMBER IS
V_bal NUMBER: = 0;
-- If dbms_output takes effect during SQL/PLUS execution, run [SET SERVEROUTPUT ON] first ];
BEGIN
Select agmt_bal
Into v_bal
From edw_t01_agmt_bal_h
Where agmt_no = P_agmt_no;
RETURN v_bal;
EXCEPTION
WHEN NO_DATA_FOUND THEN
Dbms_output.put_line ('No data found. Please enter a valid protocol number! ');
Return null;
WHEN TOO_MANY_ROWS THEN
Dbms_output.put_line ('too much data is returned. Please enter a valid protocol number! ');
Return null;
WHEN OTHERS THEN
Dbms_output.put_line ('exception! ');
Return null;
END fn_get_agmt_bal;
/

Note:

1. The dbms_output package is used in the function. If dbms_output takes effect when executed in SQL/PLUS, run SET SERVEROUTPUT ON first ].

2. This is a common format for handling oracle exceptions, which can be applied in other cases.

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.