PL/SQL tutorial 16: Table Auditing using DML Triggers in Oracle PL/SQL

Learn Table Auditing using DML Triggers in Oracle Database and Increase the level of security by keep an eye on user tempering your table data.
Blog :
Previous Tutorial
► DML Triggers with Examples
► Select-Into Statement:
►Sysdate Blog :
►►►Let’s Get Free Uber Cab◄◄◄
Use Referral Code UberRebellionRider and get $20 free for your first ride.

►Make sure you SUBSCRIBE and be the 1st one to see my videos!
►►►Find me on Social Media◄◄◄
Follow What I am up to as it happens on

You can also Email me at
for E-mail address please check About section

Please please LIKE and SHARE my videos it makes me happy.
Thanks for liking, commenting, sharing and watching more of our videos

This is Manish from


Navneil Naicker says:

That’s cool

siva krishna says:

for a table with single column it’s ok but what if for a table with number of columns.. i mean for old and new values.

Neha Sharma says:

while creating audit trigger for a table with multiple columns if i need to insert column name which is updated into audit table, how can u do that?

Suvrojoti bhunia says:

Can we make this trigger on a view and not directly on the main table?

Kiran Kumar Jonnalagadda says:

after execution of trigger CREATE  or REPLACE  TRIGGER  superheroes_audit
  v_user  varchar2(30);
  v_date  varchar2(30);
  SELECT user, TO_CHAR(sysdate, ‘DD/MON/YYYY HH24:MI:SS’) INTO v_user, v_date FROM dual;

   INSERT INTO sh_audit (new_name,old_name, user_name, entry_date, operation)
   VALUES(:NEW.SH_NAME, Null , v_user, v_date, ‘Insert’);

   INSERT INTO sh_audit (new_name,old_name, user_name, entry_date, operation)
   VALUES(NULL,:OLD.SH_NAME, v_user, v_date, ‘Delete’);

   INSERT INTO sh_audit (new_name,old_name, user_name, entry_date, operation)
   VALUES(:NEW.SH_NAME, :OLD.SH_NAME, v_user, v_date,’Update’);

I am getting following error :

Error starting at line : 7 in command –
v_date  varchar2(30)
Error report –
Unknown Command

SP2-0552: Bind Variable “NEW” is not declared.

PL/SQL procedure successfully completed.

anitha reddy says:

in trigger i want to insert the a row information which been having old date into another table but condition is 1st having only five records if u insert 6th record then that one is delete how tell me condition anyone plz

Islarf says:

WHat was the “:NEW”, “:OLD”. I tried executing this code and it wanted binds or something.

esona dotwana says:

Awesome staff thumbs up enjoying your tutorials

haribabu kallagunta says:

can you please give us a video on table audit trigger
about the table having multiple columns

Vishal Suryavanshi says:

MANISH…… Question,
where does sh_name comes from?? and m facing error Trigger is invalid :/

Doom Slayer says:

This worked for me. Excellent!

Luis Agustin Ferreras Recio says:

Hi, excelent video, i want to know how to make this for any change in any column from table or for any table in complete schema.

Antriksh Kethwas says:

helpful af

Sandeep Panda says:

I have one doubt- I dont see that the dbms_output.put_line is mentioned anywhere in the code than how the output is showing as one row is inserted by HR?

Azkia Mumarisatul Haq says:

thank you very much manish from rebelion rider

Pallavi Chatrath says:

sir pls upload procedre videos as soon as possible after trigger and upload the interview questions with answer

Chandana Pradeep says:

i have a doubt in select user line….what does the dual mean?????????????

ebiware gbenmo says:

how can i get a code to audit trigger that works with loop ,

akanksha dixit says:

why are u using here superheroes table instead of sh_audit table?

Abdul majeed says:

Can we use :old and :new if we use after in trigger?

balram pandey says:

hello, sir I am getting this following error while compiling script of complex trigger for auditing.
Error report:
Unknown Command
Bind Variable “NEW” is NOT DECLARED
anonymous block completed

асыл балгабай says:

where you created superheroes table

Jose Nardulli says:

Thanks for the tutorials manish, are you planing on doing one on FORMS and REPORTS, from installation and everything, if you do ill be very interested

sanju m says:

Shame on those who dislike the video…

Yves Rivera says:

Why are we using “BEFORE” on DML when we are actually checking “AFTER” the DML was executed?

srabana behera says:

Hi manish
I have question
Q) let’s consider a string ‘SRABANA KUMAR BEHERA’
i want to bring 2 character from each word like ‘SRKUBE’ how can I?

Gulzar siddique says:

sir if want to audit whole table ???
can i use :OLD.table_name ????

or is there any other trick to audit more than one column in a table???


abdalla afq says:

its work but the message (one row inserted by hr ) not showing what i should i do

Merry Anne Barolo says:

If I have many users on my application how can I know who the REAL user that inserted or updated the data on the table?

Abdul majeed says:

Awesome Best stuff for learning PL SQL and SQL . Really great work especially in this video as showing the real time use boosts my interest further. I am watching all the videos in the playlist of PL SQL

ZATKOP6287 says:

Your awesome man …!!!!

Debajyoti Dutta says:

What happens if HR user rollbacks a DML operation done?

mihir kar says:

Below error occer when i try to process dml on a table which also has a trigger in same table
the requrement based on after dml how to handel such senario .

3 ON triggertest
5 declare
6 pragma autonomous_transaction;
9 insert into triggertest (ib,id) values(user,sysdate);
10 elsif UPDATING then
11 insert into triggertest(ub,ud) values(user,sysdate);
12 end if;
13 commit;
14* END;
SQL> /

Trigger created.

SQL> insert into triggertest(empno,ename,sal) values(1234,’JAMES’,890);
insert into triggertest(empno,ename,sal) values(1234,’JAMES’,890)
ERROR at line 1:
ORA-00036: maximum number of recursive SQL levels (50) exceeded
ORA-06512: at “SCOTT.AUTOINSERT”, line 5
ORA-04088: error during execution of trigger ‘SCOTT.AUTOINSERT’
ORA-06512: at “SCOTT.AUTOINSERT”, line 5
ORA-04088: error during execution of trigger ‘SCOTT.AUTOINSERT’
ORA-06512: at “SCOTT.AUTOINSERT”, line 5
ORA-04088: error during execution of trigger ‘SCOTT.AUTOINSERT’
ORA-06512: at “SCOTT.AUTOINSERT”, line 5

alo doli says:

this tutorial was simply godlike

bengalifob2 says:

You’re better than my textbook and crappy college instructor combined

LogicalX says:


Vivek says:

nice explanation but i want how debugging the pl/sql code and how to return more than one value by using ref cursor.. pls upload that related videos.. 🙂

Slobodan Tajisic says:

Thanks Manish. Learning from your tutorials is a real pleasure…

karishma shrestha says:

best tutorial thankyou so much 🙂

varun dwivedi says:

sir here what is the difference between using triggers or simply using DML like insert delete and update commands …please help me.

Qorxmaz Meherremov says:


Gulzar siddique says:

sir , can we use multiple source column names in this program??????

 Write a comment


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!