Current location - Music Encyclopedia - Today in History - How to query deleted records in oracle table?
How to query deleted records in oracle table?
You can define a trigger to write deleted records to the log table, as shown below.

Test method:

Create the original table and insert data:

Create? Table? Testing?

(id? int,

Name? varchar 2( 10));

Insert? Become? Testing? Values? (1,' Zhang San');

Insert? Become? Testing? Values? (2)' Li Si';

Submit; Create a log table:

Create? Table? Test log

(id? int,

Name? varchar2( 10),

Date of deletion? Date); Create a trigger:

Create? Or? Replace? Trigger? Test _ Delete _ Test

Before? Delete? Open? test

For what? Every one? row

begin

Insert? Become? Test log (id, name, deletion date)

Values (? :old.id,? :old.name,? sysdate);

End; To delete:

Delete? From where? Testing? Where is it? id = 2;

Submit; Test the test table and the test_log table:

Therefore, it can be proved that the deletion is successful, and the deleted data is written into the log table.