Oracle第13课.doc

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Oracle第13课

第13章 异常处理一.异常基本知识1.异常分类:预定义异常,自定义异常二.预定义异常1.no_data_found 未找到数据异常2.too_many_rows 返回过多记录异常3.others 其他异常语法:exceptionwhen 异常1 then处理语句;when 异常2 then处理语句;when others then 必须最后一句处理语句;例:declarev_sname student.sname%type;beginselect sname into v_sname from student where sno=250;dbms_output.put_line(v_sname);exceptionwhen no_data_found thendbms_output.put_line(数据没有找到!);when too_many_rows thendbms_output.put_line(数据不唯一,请使用游标!);when others thendbms_output.put_line(这个比较怪,没见过!);end;/例:declare v_sname student.sname%type; begin select sname into v_sname from student; dbms_output.put_line(v_sname); exception when no_data_found then dbms_output.put_line(数据没有找到!); when too_many_rows then dbms_output.put_line(数据不唯一,请使用游标!); when others then dbms_output.put_line(这个比较怪,没见过!); end; /题1:查看员工表中是否有superman这个人,如果有工资加100,如果没有插入一条记录(只需插入employee_id,last_name,salary为0,即可)declare v_salary employees.salary%type; begin select salary into v_salary from employees where last_name=superman; update employees set salary=v_salary+100 where last_name=superman; exception when no_data_found then insert into employees(employee_id,last_name,salary) values(250,superman,0); end; /三.自定义异常1.格式:声明?触发?引用声明声明声明部分执行部分Raise 异常触发引用异常处理部分例:declaresalary_level varchar(20);e_salary_level exception; 声明beginsalary_level:=d;if salary_level not in (a,b,c) thenraise e_salary_level; 触发end if;exceptionwhen e_salary_level then 引用dbms_output.put_line(没有这个级别,没法给钱!);end;/题:求学号为2000012的学生所有课程的平均分,如果平均分小于85,打印:没考好,失误了,否则打印:正常发挥(利用自定义异常来做)declarev_avg_grade sc.grade%type;e exception;beginselect avg(grade) into v_avg_grade from sc where sno=2000012;if v_avg_grade85 thenraise e;end if;dbms_output.put_line(很好);exceptionwhen e thendbms_output.put_line(这样不好!);end;/

文档评论(0)

cgtk187 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档