declare i number; em emp%rowtype; begin -- i:=8/0; -- i='aaaa'; -- select * into em from emp; select * into em from emp where empno=1234567; exception when zero_divid e then dbms_output.put_line('除0 异常'); when value_error then dbms_output.put_line('数值转换异常'); when too_many_rows then dbms_output.put_line('查询出多行记录,但是赋值给了rowtype记录一行数据变量'); -- when no_data_found then -- dbms_output.put_line('没有找到数据异常'); when others then dbms_output.put_line('发生了其它异常' || sqlerrm); end; select * from emp where empno=73691;
declare --声明游标 cursor vrows is select * from emp where empno=8888; --声明一个记录型变量 vrow emp%rowtype; --声明一个自定义异常 no_emp exception; begin --1.打开游标 open vrows; --2.取数据 fetch vrows into vrow;-- 默认取第一行 --3.判断游标是否有数据 if vrows%notfound then raise no_emp; end if; close vrows; exception when no_emp then dbms_output.put_line('发生了自定义的异常'); end;