您的位置:首页 > 数据库

PL_SQL基础--续三

2009-06-01 00:37 239 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: