簡體   English   中英

Oracle如何計算在plsql塊中插入的總行數

[英]Oracle How to count total number of rows inserted in a plsql block

我想不計入數據庫的插入次數

盡管更新了2行,但以下查詢返回one(1)

begin 
   Insert into APPLICATIONS (ID,ALIAS,NAME,STATUS) 
        values (1000000386,'BB','Branch Budgets','I'));
   Insert into APPLICATIONS (ID,ALIAS,NAME,STATUS) 
        values (1000000257,'TIME','Timesheets','I'));
   dbms_output.put_line('No Of rows'||sql%Rowcount);
 end;
dbms_output.put_line('No Of rows'||sql%Rowcount);

這將為您提供由上一條語句更新的總行數。 因此,即使您以這種方式有10條插入語句,您也將始終獲得1作為sql%rowcount

使用2條輸出語句,在insert語句之后各使用1條輸出語句,或者使用變量並添加更新后的行數,然后最后顯示它。

declare
    v_count integer;
    begin 
        v_count:=0;
       Insert into APPLICATIONS (ID,ALIAS,NAME,STATUS) 
            values (1000000386,'BB','Branch Budgets','I');
        v_count:=   sql%Rowcount;
       Insert into APPLICATIONS (ID,ALIAS,NAME,STATUS) 
            values (1000000257,'TIME','Timesheets','I');
        v_count:= v_count+ sql%Rowcount;
       dbms_output.put_line('No Of rows '||v_count);
     commit;
     end;

或如果要將數據插入到同一表中,請使用組合的insert語句,如下所示。 這將返回2行。

begin    
    INSERT ALL 
        into  APPLICATIONS (ID,ALIAS,NAME,STATUS) 
             values (1000000386,'BB','Branch Budgets','I')
        into  APPLICATIONS (ID,ALIAS,NAME,STATUS) 
             values (1000000257,'TIME','Timesheets','I')
    SELECT * FROM dual;         
    dbms_output.put_line('No Of rows '||sql%Rowcount);
    commit;
    end;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM