Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7043687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:19:12+00:00 2026-05-28T02:19:12+00:00

I have a statement level trigger that fires whenever INSERT UPDATE or DELETE operations

  • 0

I have a statement level trigger that fires whenever INSERT UPDATE or DELETE operations are performed on a table (called customers). I want to display a message (to DBMS_OUTPUT) containing the number of rows that were inserted/updated/deleted.

I just want one message for each triggering statement, eg
‘4 rows were inserted into customers table’.

How can I access the number of rows that are affected by the triggering statement from INSIDE the trigger declaration, ie XXX in the code below:

CREATE OR REPLACE TRIGGER customer_changes_trigger_2
AFTER INSERT OR UPDATE OR DELETE ON customers

DECLARE
v_operation   VARCHAR(10);
v_number_rows NUMBER;


BEGIN

v_number := XXX;

IF INSERTING THEN
   v_operation := 'inserted';
END IF;

IF UPDATING THEN
   v_operation := 'updated';
END IF;

IF DELETING THEN
   v_operation := 'deleted';
END IF;

DBMS_OUTPUT.PUT_LINE
          (v_number_rows|| ' rows were ' || v_operation || ' from customers.');
END;

Can’t find anything in the documentation, any help appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:19:13+00:00Added an answer on May 28, 2026 at 2:19 am

    One way is to use a global variable to track the number of rows as there is no other way to get the row count from a statement level trigger. You would then need three triggers… one statement level to initialise the variable before the statement is run, one row level to add one to the variable for each row, one statement level to use the row count however you wish. First, set up the variable and a few procedures to help it:

    create or replace package PKG_ROWCOUNT is
      NUMROWS   number;
    
      procedure INIT_ROWCOUNT;
    
      procedure ADD_ONE;
    
      function GET_ROWCOUNT
        return number;
    end PKG_ROWCOUNT;
    /
    
    create or replace package body PKG_ROWCOUNT as
      procedure INIT_ROWCOUNT is
      begin
        NUMROWS := 0;
      end;
    
      procedure ADD_ONE is
      begin
        NUMROWS := Nvl(NUMROWS, 0) + 1;
      end;
    
      function GET_ROWCOUNT
        return number is
      begin
        return NUMROWS;
      end;
    end PKG_ROWCOUNT;
    /
    

    The first trigger to initialise the variable:

    create or replace trigger CUSTOMER_CHANGES_TRIGGER_1
      before insert or update or delete
      on CUSTOMERS
    begin
      PKG_ROWCOUNT.INIT_ROWCOUNT;
    end;
    

    The second to update per row:

    create or replace trigger CUSTOMER_CHANGES_TRIGGER_2
      after insert or update or delete
      on CUSTOMERS
      for each row
    begin
      PKG_ROWCOUNT.ADD_ONE;
    end;
    /
    

    The third to display the total:

    create or replace trigger CUSTOMER_CHANGES_TRIGGER_3
      after insert or update or delete
      on CUSTOMERS
    begin
       Dbms_output.
       PUT_LINE(PKG_ROWCOUNT.GET_ROWCOUNT || ' rows were affected.');
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have LINQ statement that looks like this: return ( from c in customers
I have a T-SQL statement that I am running against a table with many
I have an insert statement that was deadlocking using linq. So I placed it
I have a statement similar to this that I need to run in Linq.
In an Oracle 10g environment, I have a statement that needs to be executed
I have three level hierarchical data. using the statement below i managed to display
I have the following method that works well, except the yield break statement only
I have been trying to add columns to a table using some logic that
Using SQL2k5, I have a staging table that contains columns that will populate numerous
If right after BEGIN I have SET TRANSACTION ISOLATION LEVEL ... statement, will the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.