Plsql 在处理异常后写入回滚
我有一个场景,在这个场景中,我像这样写异常Plsql 在处理异常后写入回滚,plsql,Plsql,我有一个场景,在这个场景中,我像这样写异常 when others then rollback; p_status := 'ERROR'; -- MODIFIED p_status_dtl := sqlcode||' - '||substr(sqlerrm,1,100); end; exception when others then p_status := '
when others then
rollback;
p_status := 'ERROR'; -- MODIFIED
p_status_dtl := sqlcode||' - '||substr(sqlerrm,1,100);
end;
exception
when others then
p_status := 'ERROR'; -- MODIFIED
p_status_dtl := sqlcode||' - '||substr(sqlerrm,1,100);
rollback;
end;
如果我这样写
when others then
rollback;
p_status := 'ERROR'; -- MODIFIED
p_status_dtl := sqlcode||' - '||substr(sqlerrm,1,100);
end;
exception
when others then
p_status := 'ERROR'; -- MODIFIED
p_status_dtl := sqlcode||' - '||substr(sqlerrm,1,100);
rollback;
end;
有区别吗?如果有,区别是什么 如果变量赋值没有抛出(即
p\u status
和p\u status\u dtl
都是具有足够存储的正确数据类型),则示例是相同的
如果变量赋值抛出,则在第二个示例中,rollback
不会执行
在下面的示例中,仅打印检查点1:
declare
v_foo varchar2(2) := 'AB';
v_bar number;
begin
-- raises ORA-01476: divisor is equal to zero
v_bar := 1/0;
exception
when others then
dbms_output.put_line('checkpoint 1');
-- raises ORA-06502: PL/SQL: numeric or value error: character string buffer too small
v_foo := 'TOO LONG';
dbms_output.put_line('checkpoint 2');
end;
/
如果变量赋值没有抛出(即
p_status
和p_status\u dtl
都是正确的数据类型,并且有足够的存储空间),则示例是相同的
如果变量赋值抛出,则在第二个示例中,rollback
不会执行
在下面的示例中,仅打印检查点1:
declare
v_foo varchar2(2) := 'AB';
v_bar number;
begin
-- raises ORA-01476: divisor is equal to zero
v_bar := 1/0;
exception
when others then
dbms_output.put_line('checkpoint 1');
-- raises ORA-06502: PL/SQL: numeric or value error: character string buffer too small
v_foo := 'TOO LONG';
dbms_output.put_line('checkpoint 2');
end;
/
如果变量赋值没有抛出(即
p_status
和p_status\u dtl
都是正确的数据类型,并且有足够的存储空间),则示例是相同的
如果变量赋值抛出,则在第二个示例中,rollback
不会执行
在下面的示例中,仅打印检查点1:
declare
v_foo varchar2(2) := 'AB';
v_bar number;
begin
-- raises ORA-01476: divisor is equal to zero
v_bar := 1/0;
exception
when others then
dbms_output.put_line('checkpoint 1');
-- raises ORA-06502: PL/SQL: numeric or value error: character string buffer too small
v_foo := 'TOO LONG';
dbms_output.put_line('checkpoint 2');
end;
/
如果变量赋值没有抛出(即
p_status
和p_status\u dtl
都是正确的数据类型,并且有足够的存储空间),则示例是相同的
如果变量赋值抛出,则在第二个示例中,rollback
不会执行
在下面的示例中,仅打印检查点1:
declare
v_foo varchar2(2) := 'AB';
v_bar number;
begin
-- raises ORA-01476: divisor is equal to zero
v_bar := 1/0;
exception
when others then
dbms_output.put_line('checkpoint 1');
-- raises ORA-06502: PL/SQL: numeric or value error: character string buffer too small
v_foo := 'TOO LONG';
dbms_output.put_line('checkpoint 2');
end;
/