受PL/SQL中的UPDATE影响的行数 [英] Number of rows affected by an UPDATE in PL/SQL

查看:79
本文介绍了受PL/SQL中的UPDATE影响的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PL/SQL函数(在Oracle 10g上运行),在其中更新了一些行.有没有办法找出UPDATE影响了多少行?手动执行查询时,它告诉我受影响的行数是多少,我想在PL/SQL中获取该数字.

I have a PL/SQL function (running on Oracle 10g) in which I update some rows. Is there a way to find out how many rows were affected by the UPDATE? When executing the query manually it tells me how many rows were affected, I want to get that number in PL/SQL.

推荐答案

您使用sql%rowcount变量.

您需要在需要查找受影响行数的语句后直接调用它.

You need to call it straight after the statement which you need to find the affected row count for.

例如:

set serveroutput ON; 
DECLARE 
    i NUMBER; 
BEGIN 
    UPDATE employees 
    SET    status = 'fired' 
    WHERE  name LIKE '%Bloggs'; 
    i := SQL%rowcount; 
    --note that assignment has to precede COMMIT
    COMMIT; 
    dbms_output.Put_line(i); 
END; 

这篇关于受PL/SQL中的UPDATE影响的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆