Oracle PL/SQL Learning Basics (2)-Exceptions

Source: Internet
Author: User

1. Exception Classification: System exceptions, custom exceptions

(1) System exceptions, see related API documentation

(2) Custom exceptions

Define your own exceptions: As with custom variables, the type is exception

Exception thrown: Use raise to throw a custom exception

SetServeroutput onDeclare    cursorCemp is SelectEname fromEmpwhereDeptno= -; Pename Emp.ename%type; --Self define exceptionSelf_no_data_found exception;begin    OpenCemp; FetchCemp intoPename; ifCemp%NotFound Then        --throw self Define exceptionraise Self_no_data_found; End if; exception whenSelf_no_data_found ThenDbms_output.put_line ('A custom exception was executed! '); ifCemp%IsOpen ThenDbms_output.put_line ('Close cursor! '); CloseCemp; End if;  whenOthers ThenDbms_output.put_line ('others exception was performed! '); ifCemp%IsOpen Then         CloseCemp; End if;End;/

Operation Result:

Oracle PL/SQL Learning Basics (2)-Exceptions

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.