Connecting Tech Pros Worldwide Forums | Help | Site Map

Populating a table using trigger

Newbie
 
Join Date: May 2007
Posts: 8
#1: Jul 17 '07
Hi,
I am inserting data in table1.using a trigger I want to populate TABLE2.My code is like this :
TABLE1 :ST_INFO
FIELDS : NAME (varchar),ACCOUNT_TYPE(varchar),TIME(date)
TABLE2 :TOTALS
FIELDS : CURR_DAY(date),DISCONNECTIONS(number)
I am inserting data in ST_INFO using SQLLOADER.I want to populate TOTALS with the TIME,count of TIME field after insertion.
CREATE OR REPLACE TRIGGER TRI_TOTALS
AFTER INSERT ON ST_INFO FOR EACH ROW
BEGIN
IF(:NEW.TIME=:OLD.TIME) THEN
UPDATE TOTALS SET CURR_DAY=:OLD.TIME;
ELSE
INSERT INTO TOTALS(CURR_DAY) VALUES(:NEW.TIME);
END IF;
END;

With this only INSERTION operation is happening not UPDATION.
Can anybody help me ? and suggest a way to insert DISCONNECTIONS value in TABLE2.

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,511
#2: Jul 18 '07

re: Populating a table using trigger


do u have any existing data in the TOTALS table ?
Newbie
 
Join Date: May 2007
Posts: 8
#3: Jul 18 '07

re: Populating a table using trigger


Quote:

Originally Posted by debasisdas

do u have any existing data in the TOTALS table ?

I have initialized the fields of TOTALS with NULL values.
Reply