Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Plsql 在处理异常后写入回滚_Plsql - Fatal编程技术网

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;
/