Exception classification and its processing in PL/SQL language programming

Source: Internet
Author: User

--Pre-defined exception: The system has declared an exception
DECLARE
V_name EMP. Ename%type;
BEGIN
SELECT ename to V_name from EMP WHERE EMPNO = 1234;
EXCEPTION
When No_data_found Then
Dbms_output. Put_Line (' No data found ');
When OTHERS Then
Dbms_output.put_line (' other anomalies ');
END;

--Non-predefined exception: System exception, the system does not declare it
DECLARE
E_fkexception EXCEPTION;
PRAGMA Exception_init (e_fkexception,-2291);
BEGIN
INSERT into EMP VALUES (8888, ' Tom ', ' Clerk ', 7902,sysdate,1900,null,50);
EXCEPTION
When E_fkexception Then
Dbms_output.put_line (' foreign key exception! ');
When OTHERS Then
Dbms_output.put_line (' other anomalies ');
END;


--User-defined exception
DECLARE
E_salexception EXCEPTION;
V_sal Emp.sal%type;
V_empno Emp.empno%type: = &no;
BEGIN
SELECT sal into v_sal from emp WHERE empno = v_empno;
IF V_sal <
RAISE e_salexception;
END IF;
EXCEPTION
When E_salexception Then
Dbms_output.put_line (' wages cannot be less than 1000! ');
END;

Exception classification and its processing in PL/SQL language programming

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.