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