Number of rows affected by an UPDATE in PL/SQL(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 影响的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PL/SQL 中受 UPDATE 影响的行数
基础教程推荐
- SQL Server 2016更改对象所有者 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01