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

查看:51
本文介绍了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天全站免登陆