1、记录已存在 ,违反唯一限制:ORA-00001 insert into student values(‘1111’,‘张小龙’,‘女’,17,‘04’); 2、违反外键约束:ORA-02291 insert into student values(‘1111b’,‘张小龙’,‘女’,17,‘06’); 3、引用的数据不存在 insert into student(sno,sname,ssex,sage,deptno) values(‘1111b’,‘张小龙’,‘女’,17,‘06’); 4、输入的数据不够:ORA-00947 insert into student values(‘1111b’,‘张小龙’,‘女’,17); 5、值过多:ORA-00913 insert into student values(‘1111b’,‘张小龙’,‘女’,17,‘06’,‘sadad’);
例1、删除数据产生异常
declare err_delereferences exception; pragma exception_init(err_delereferences,-02292); begin delete from course where cno=&cno; exception when err_delereferences then dbms_output.put_line('被其它数据引用'); when others then dbms_output.put_line('其他'); end;2、子查询时产生的异常(没获得数据)
declare v_grade score.grade%type; err_subnodata exception; pragma exception_init(err_subnodata,-01427); begin select grade from score where sno in(select sno from student where sname='安然') ; exception when err_subnodata then dbms_output.put_line('子查询时没获得数据'); when others then dbms_output.put_line('其他'); end;