Hi, I have posted a thread regarding the trigger under the name polaris_ws on 4/1/2003. But the code from these experts didn't work. I just want to know anybody on this forum can give me a help. The purpose is to insert one row of row count number and total amount into an audit table. However, the trigger fire to insert data more than once. How can I control this through the PL/SQL code. I post the trigger code as follows. If I assign the value to MAX_ROWS number:= 7659, Then the trigger will only fire once to insert one row like this:
AUDIT_NUM STG_ROW STG_AMOUNT RENEW_DATE
1 7659 175668920 4/1/2003

This trigger is statement level trigger. It should logically fire after the transaction. I don't know why it fire many times ( less than total row inserted into the table).
******************************************************************
CREATE OR REPLACE TRIGGER BOPSUM_Q
AFTER INSERT OR UPDATE ON NDW_BOP_DETAIL_Q
DECLARE
STG_ROWS NUMBER;
STG_AMOUNT NUMBER;
RENEW_DATE DATE;
MAX_ROWS NUMBER;
BEGIN

SELECT COUNT(NDW_TRANS_NO)STG_ROWS, SUM(AMOUNT)STG_AMOUNT
INTO STG_ROWS, STG_AMOUNT
FROM NDW_BOP_DETAIL_Q;


SELECT MAX(NDW_TRANS_NO)INTO MAX_ROWS FROM NDW_BOP_DETAIL_Q;


IF STG_ROWS = MAX_ROWS THEN


INSERT INTO BOP_DETAIL_AUDIT (AUDIT_NUM, STG_ROWS, STG_AMOUNT, RENEW_DATE)
VALUES (BOP_SEQ.NEXTVAL, STG_ROWS, STG_AMOUNT, SYSDATE);

END IF;

END BOPSUM_Q;
/