create truncate trigger
471157Apr 22 2009 — edited Apr 22 2009Hi guys,
I want to create a trigger as follows
CREATE OR REPLACE TRIGGER ON_T_temp
before truncate on schema
WHEN (ora_dict_obj_name='T_TEMP' AND ora_dict_obj_TYPE='TABLE')
declare
p_count NUMBER(9):=0;
BEGIN
select count(*) into p_count
from T_TEMP;
if p_count > 0 then
for c1 in (select LOC_CODE,BATCH_NO,BILL_MONTH
from T_TEMP)
loop
insert into t_temp_log
(loc_code
,BATCH_NO
,BILL_MONTH
,date_time
)
VALUES
(c1.loc_code
,c1.BATCH_NO
,c1.BILL_MONTH
,SYSDATE
);
end loop;
end if;
COMMIT;
END;
/
Trigger created.
SQL> insert into t_temp values(445201,11,20090101);
1 row created.
SQL> insert into t_temp values(445201,11,20090201);
1 row created.
SQL> insert into t_temp values(445201,11,20090301);
1 row created.
SQL> commit;
Commit complete.
SQL> truncate table t_temp;
Table truncated.
SQL> select * from t_temp_log;
no rows selected.
Here Table t_temp_log shows no records after truncate table.
No record has been inserted into table t_temp_log before truncate table.
Please help me how this trigger will work.