Oracle Plsql Exception Exceptions

Source: Internet
Author: User

Not_data_found Exceptions:

--out of system columnsSetServeroutput onDeclarepename Emp.ename%type; begin  SelectEname intoPename fromEmpwhereEmpno=1234; Exception whenNo_data_found ThenDbms_output.put_line ('No data found');  whenOthers ThenDbms_output.put_line ('other'); End;/

Too_many_rows Exceptions:

1 --System exception: Too_many_rows2 3 SetServeroutput on4 Declare5 6Pename Emp.ename%type;7 8 begin9 Ten   SelectEname intoPename fromEmpwhereDeptno= Ten; One  A Exception -    whenToo_many_rows ThenDbms_output.put_line ('SELECT into matches multiple lines'); -    whenOthers ThenDbms_output.put_line ('other'); the End; - /

Arithmetic or conversion exceptions:

1 --System exception: Value_error2 3 SetServeroutput on4 5 Declare6   7Pnum Number;8 begin9Pnum:= 'ABC';Ten    One Exception A    whenValue_error ThenDbms_output.put_line ('arithmetic or conversion errors'); -    whenOthers ThenDbms_output.put_line ('other'); - End; the /

0 cannot do divisor exceptions:

1 --System Exception Zero_divide2 SetServeroutput on3 4 Declare5 6Pnum Number;7 begin8 9Pnum:= 1/0;Ten    One Exception A    whenZero_divide ThenDbms_output.put_line ('0 cannot do divisor'); -    whenOthers ThenDbms_output.put_line ('other'); - End; the /

Custom Exceptions:

--Custom Exceptions:SetServeroutput onDeclare  cursorCemp is SelectEname fromEmpwhereDeptno= -; Pename Emp.ename%type; --out of custom columnsNot_emp_data exception; begin  OpenCemp; FetchCemp intoPename; ifCemp%NotFound Thenraise Not_emp_data; End if; --Oracle automatically shuts down cleanup resources through Pmon (Process Monitor) if exceptions occur in the program  CloseCemp; Exception whenNot_emp_data ThenDbms_output.put_line ('Custom Exception: No query to Data');  whenOthers ThenDbms_output.put_line ('Outside other columns');End;/

Knowledge Point Source: http://www.imooc.com/learn/360

Oracle Plsql Exception 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.