测试 SQL 过程异常检查
Testing SQL Procedure Exception Check
我在 Oracle SQL Developer 11g 上创建了以下 PL/SQL 过程,并想强制测试异常以确保我编码到其中的电子邮件确实在异常时发送出去发生。有人可以告诉我该怎么做吗?
create or replace
procedure Procedure_1 as
-- This script updates the 'owner_id' field on Schema.table1 to 'SYSADMIN' for FISCAL, BREAKDWN, and PROGRAM table types.
--
v_code number;
v_errm varchar2(512);
vOM_Recipients VARCHAR2(200) := 'personal_email@email.com';
begin
update Schema.table1
set owner_id = 'SYSADMIN'
where table_type in ('FISCAL','BREAKDWN','PROGRAM') and owner_id <> 'SYSADMIN';
commit;
EXCEPTION
WHEN OTHERS THEN
v_code := SQLCODE;
v_errm := SUBSTR(SQLERRM, 1 , 512);
UTL_MAIL.send(sender => 'automated_email@email.com',
recipients => vOM_Recipients,
subject => 'Procedure_1 Job Error',
message => 'Procedure_1 Job Error.' || chr(10) || chr(10) ||
'The error code is '||v_code||'-'||v_errm||' ');
end;
来自 Justin Cave 的评论:
如果你只是想抛出一个随机错误 raise_application_error(-20001, 'Some Random Message');
我在 Oracle SQL Developer 11g 上创建了以下 PL/SQL 过程,并想强制测试异常以确保我编码到其中的电子邮件确实在异常时发送出去发生。有人可以告诉我该怎么做吗?
create or replace
procedure Procedure_1 as
-- This script updates the 'owner_id' field on Schema.table1 to 'SYSADMIN' for FISCAL, BREAKDWN, and PROGRAM table types.
--
v_code number;
v_errm varchar2(512);
vOM_Recipients VARCHAR2(200) := 'personal_email@email.com';
begin
update Schema.table1
set owner_id = 'SYSADMIN'
where table_type in ('FISCAL','BREAKDWN','PROGRAM') and owner_id <> 'SYSADMIN';
commit;
EXCEPTION
WHEN OTHERS THEN
v_code := SQLCODE;
v_errm := SUBSTR(SQLERRM, 1 , 512);
UTL_MAIL.send(sender => 'automated_email@email.com',
recipients => vOM_Recipients,
subject => 'Procedure_1 Job Error',
message => 'Procedure_1 Job Error.' || chr(10) || chr(10) ||
'The error code is '||v_code||'-'||v_errm||' ');
end;
来自 Justin Cave 的评论: 如果你只是想抛出一个随机错误 raise_application_error(-20001, 'Some Random Message');