2014-01-14 60 views

回答

5

有没有简单的方法来获取执行的语句的数量,或受影响的行的累计计数。你需要添加代码来跟踪你自己。对于语句的数量,您可以在每次执行时将一个变量添加到变量中。对于受影响的行数,你可以使用SQL%ROWCOUNT implicit cursor attribute

declare 
    statement_count pls_integer := 0; 
    total_row_count pls_integer := 0; 
begin 
    insert into my_table (id) values (1); 
    statement_count := statement_count + 1; 
    total_row_count := total_row_count + SQL%ROW_COUNT; 
    dbms_output.put_line('Rows affected by statement ' || statement_count 
    || ': ' || SQL%ROWCOUNT); 

    update my_table set id = id + 1; 
    statement_count := statement_count + 1; 
    total_row_count := total_row_count + SQL%ROW_COUNT; 
    dbms_output.put_line('Rows affected by statement ' || statement_count 
    || ': ' || SQL%ROWCOUNT); 

    delete from my_table where id = 2; 
    statement_count := statement_count + 1; 
    total_row_count := total_row_count + SQL%ROW_COUNT; 
    dbms_output.put_line('Rows affected by statement ' || statement_count 
    || ': ' || SQL%ROWCOUNT); 

    dbms_output.put_line('Number of statements: ' || statement_count); 
    dbms_output.put_line('Total rows affected: ' || total_row_count); 
end; 
/

你需要,如果你只在提交的数值兴趣commitrollback后的计数器(S)重置,如果你要成为做那中间块;尽管这通常不是必要的或者是一个好主意。

+0

正如我怀疑......没有FOO%STATEMNTCOUNT,我们必须一一计算。 –