PL_SQL基础--续三

来源:互联网 发布:淘宝秒杀回答问题技巧 编辑:程序博客网 时间:2024/05/17 04:09

DBA通常建立error日志:
 1.建立日志表:
 create table errorlog
 (
 id number primary key,
 errcode number,
 errmsg varchar2(1024),
 errdate date
 );

 2.建立序列
 create sequence seq_errorlog_id start with 1 increment by 1;

 3.PL_SQL中运用
 declare
  v_deptno dept.deptno%type := 10;
  v_errcode number;
  v_errmsg varchar2(1024);
 begin
  delete from dept where deptno = v_deptno;
  commit;
 exception
  when others then
   rollback;
   v_errcode := SQLCODE;
   v_errmsg := SQLERRM;
  insert into errorlog values(seq_errorlog_id.nextval,v_errcode,v_errmsg,sysdate);
   commit;
 end;
 --查看出错具体时间
 select to_char(errdate,'YYYY-MM-DD HH24:MI:SS') from errorlog;

原创粉丝点击