简体   繁体   English

Oracle 交易 PLSQL

[英]Oracle Transactions PLSQL

I am working on PLSQL based Procedures in Oracle 11g & 12c.我正在研究 Oracle 11g 和 12c 中基于 PLSQL 的程序。

I want to keep logs of table name and row count when I issue commit command in one of my procedure/function.当我在我的一个过程/函数中发出提交命令时,我想保留表名和行数的日志。

This is for audit logs.这是用于审计日志。

Can you please suggest how do I accomplish this?你能建议我如何做到这一点吗?

Your PL/SQL code will need to keep track of its activity and log it.您的 PL/SQL 代码将需要跟踪其活动并记录它。 There is no way to ask Oracle "how many rows are you committing right now and to which tables?"没有办法问 Oracle “你现在提交了多少行以及哪些表?”

So, eg,所以,例如,

DECLARE
  l_row_count NUMBER; 
BEGIN
  UPDATE table_1 SET column_a = 'whatever' WHERE column_b = 'some condition';

  l_row_count := SQL%ROWCOUNT;

  INSERT INTO my_audit ( action, cnt ) VALUES ('Updated table_1', l_row_count);
  -- Notice the audit is part of the transaction; if I don't commit the UPDATE,
  -- I won't commit the log of the update.

  -- ... do other similar updates / inserts / deleted, using SQL%ROWCOUNT to 
  -- to determine the number of rows affected and log each one ...

  COMMIT;
END;

Again, it is not practical to do a bunch of DML statements (inserts, updates, deletes) and then ask Oracle after the fact "what I have done so far in this transaction?"同样,执行一堆 DML 语句(插入、更新、删除)然后在“到目前为止我在此事务中做了什么?”之后询问 Oracle 是不切实际的。 You need to record it as you go.您需要将其记录为 go。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM