How Does Oracle restore the data of a table accidentally deleted?

Source: Internet
Author: User
Due to accidental deletion of Oracle table data, this data may be very important. How to quickly restore the data so that the supervisor does not discover it can write a stored procedure to restore the first data deleted

Due to accidental deletion of Oracle table data, this data may be very important. How to quickly restore the data so that the supervisor does not discover it can write a stored procedure to restore the first data deleted

Due to accidental deletion of Oracle table data, the data may be very important. How to quickly restore the data so that the supervisor does not discover it can write a stored procedure ,, restore the data at the previous time point of data deletion

Create or replace procedure pro_recover_del_data (
Ai_table_name in varchar2, -- Name of the table of the accidentally deleted data
Ai_data_time in varchar2, -- restore to a time point before data deletion
Ao_success out varchar2, -- whether it is successful 1: Successful, 0: Failed
Op_msg out varchar2 -- prompt message
)
Authid Current_User
Is
Sqlstring varchar2 (1000 );
Begin

Delete from RELA_T_RELASET;
Sqlstring: = 'insert into' | ai_table_name | 'select * from' | ai_table_name | 'as of timestamp to_timestamp ('| ''''
| Ai_data_time | ''' | ',' | ''' | 'yyyy-mm-dd hh24: mi: ss' | ''' | ')';
Execute IMMEDIATE sqlstring;
Commit;
Op_msg: = 'recovery successful! ';
Ao_success: = '1 ';
Exception
WHEN Dup_val_on_index THEN
Op_msg: = 'Primary key repetition ';
WHEN Timeout_on_resource THEN
Op_msg: = 'Wait for resource timeout ';
WHEN Invalid_CURSOR THEN
Op_msg: = 'invalid curs ';
WHEN Not_logged_on THEN
Op_msg: = 'database not connected ';
WHEN Login_denied THEN
Op_msg: = 'user name/password error ';
WHEN No_data_found THEN
Op_msg: = 'select INTO no data found ';
WHEN Too_many_rows THEN
Op_msg: = 'select INTO return multiple rows of Data ';
WHEN Zero_pide THEN
Op_msg: = 'attempt to be division by zero ';
WHEN Invalid_NUMBER THEN
Op_msg: = 'failed to convert a number ';
WHEN Storage_error THEN
Op_msg: = 'internal error caused by insufficient memory ';
WHEN Program_error THEN
Op_msg: = 'internal error ';
WHEN Value_error THEN
Op_msg: = 'conversion or truncation error ';
WHEN Rowtype_mismatch THEN
Op_msg: = 'Primary cursor variables and PL/SQL variables have incompatible row type ';
WHEN CURSOR_already_OPEN THEN
Op_msg: = 'attempt to open an existing curs ';
WHEN ACCESS_INTO_NULL THEN
Op_msg: = 'attempt to access a null value ';
WHEN Collection_is_null THEN
Op_msg: = 'Access an empty collection ';
WHEN Subscript_outside_limit THEN
Op_msg: = 'try to apply the collection method other than Exists to a null pl/SQL table or varray ';
WHEN Subscript_beyond_count THEN
Op_msg: = 'reference to nested or varray indexes is greater than the number of elements in the set ';
WHEN OTHERS THEN
Op_msg: = 'other errors! ';

Rollback;
Ao_success: = '0 ';
End;


Then, call the stored procedure.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.