PL/SQL程式之例外

來源:互聯網
上載者:User
什麼是例外?例外是程式設計語言提供的一種功能,用來增強程式的健壯性和容錯性Oracle的異常處理系統定義例外No_data_found    (沒有找到資料)Too_many_rows          (select …into語句匹配多個行) Zero_Divide   ( 被零除)Value_error     (算術或轉換錯誤)Timeout_on_resource      (在等待資源時發生逾時)例一:除0例外SQL> declare  2  pnum number :=10;  3  begin  4  pnum :=pnum/0;  5  exception  6  when zero_divide then   7  dbms_output.put_line('除0啦');  8  end;  9  / 除0啦使用者定義例外及處理例外在declare節中定義例外   out_of   exception ;在可行語句中引起例外  raise out_of ;在Exception節處理例外when Out_of then …例二:使用者自訂例外declarecursor c1(emp_no number) is select * from emp where empno=emp_no;emprow emp%rowtype;no_found exception;beginopen c1(1000);fetch c1 into emprow;if c1%notfound then raise no_found;end if;close c1;exceptionwhen no_found thendbms_output.put_line('使用者自訂的例外');end;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.