It works, you must have made a typo
ops$tkyte@ORA9IR2> CREATE TABLE LOG_TAB
2 (MACHINE VARCHAR2(100),USERNAME VARCHAR2(100), IP VARCHAR2(100)) ;
Table created.
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> create or replace trigger TRG_NO_TRUNCATE_TABLE
2 before truncate on SCHEMA
3 declare
4 PRAGMA AUTONOMOUS_TRANSACTION;
5 begin
6 insert into log_tab (machine,ip, username)
7 values ( SYS_CONTEXT('USERENV', 'TERMINAL'),
8 SYS_CONTEXT('USERENV', 'IP_ADDRESS'),
9 SYS_CONTEXT('USERENV', 'OS_USER') );
10 commit;
11
12 RAISE_APPLICATION_ERROR
13 (-20998, 'truncate table is not allowed !! pls contact DBA.');
14 end;
15 /
Trigger created.
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> truncate table t;
truncate table t
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20998: truncate table is not allowed !! pls contact DBA.
ORA-06512: at line 10
ops$tkyte@ORA9IR2> select * from log_tab;
MACHINE USERNAME IP
---------- ---------- ----------
tkyte 127.0.0.1