Deleting data in table without Rollback in oracle - oracle

I have deleted data in a table and didnot rollback. Will the data in that table gets deleted permanently in oracle sql developer?

Will those rows be deleted permanently?
It depends.
if you didn't rollback, but you didn't commit either, then rows will be deleted within your own session, but any other user will still see all those rows
check SQL Developer's preferences (Database > Advanced) and see whether the Autocommit checkbox is turned on - if so, then although you didn't explicitly commit, tool did that for you. In my opinion, autocommit is generally a bad idea
even if you did commit, but there's the flashback option enabled in your database, then you can restore those rows
certainly, you should perform regular backup and be able to restore data (that won't save you from losing rows that were inserted/updated between two backups, though)
Basically, there are various options that could & should help you restore deleted rows.

You can recover deleted table records in SQL server by
Step 1: Create a Database. ...
Step 2: Insert Data into Table. ...
Step 3: Delete Rows from Table. ...
Step 4: Get Information about Deleted Rows. ...
Step 5: Get Log Sequence Number of the LOP_BEGIN_XACT Log Record. ...
Step 6: Recover Deleted Records in SQL Server.

Related

Is there any time limit on the records in table user_tab_modifications table?

I'm using user_tab_modifications table to monitor all my table's change in DB, but sometimes the records disappeared.
For example, I updated the data in table A, and ran the following SQL to flush the table user_tab_modifications so that I can see the latest information there.
exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
Then
SELECT * FROM USER_TAB_MODIFICATIONS;
So I can see the record about table A in there.
But then I found the record about table A disappeared after about 1 minute even though I didn't do anything in Oracle.
(other records in user_tab_modifications do not change. No problems)
That's why and can I do some settings to change it (make sure the records there will not disappear)? Thank you.
From the documentation:
USER_TAB_MODIFICATIONS describes modifications to all tables owned by the current user that have been modified since the last time statistics were gathered on the tables.
You might want to check if some stat gathering process was running in the background on the concerned table between the time when the changes were done and when you saw the stat record disappear.

Oracle Clear Cached Sequence

I have a very simple table that has an ID (generated by a sequence), and a NAME. I inserted a couple rows which got cached but after a while I wanted to remove them because I wanted to redo my table so I issued a couple of DELETE statements to remove all records (I don't have the privileges to do a TRUNCATE).
After deleting the old rows, I again inserted a couple other records but I didn't bother resetting the sequence.
On PHP, when I SELECT everything on that table, I still get those old deleted rows. But on PL/SQL when I SELECT on that table, it only shows me the new records.
Is the problematic cache on the PHP or Oracle side? If it's on the Oracle side, how do I clear it out?
Thanks!

Oracle Gobal Temp table issue

I am using JdbcTemplate and Oracle stored procedure. In oracle store procedure I have a select query in which I have IN clause like 'IN (SELECT ID FROM GLOBAL_TEMP_TABLE)'.
And the definition of temp table is ON COMMIT PRESERVE ROWS.
However, when I am calling stored procedure from java it give me more records than I expected, seems temp table is storing data from previous session. Need your help.
Without looking at any code, it is hard to tell.
Yet, the symptoms you describe might only be caused because you are still accessing your data from the same session.
From Oracle-Base: Global Temporary Tables (GTT):
The ON COMMIT DELETE ROWS clause indicates that the data should be deleted at the end of the transaction.
the ON COMMIT PRESERVE ROWS clause indicates that rows should be preserved until the end of the session.
That is, in your case, you need to close the session to clear the data.
You cannot access data from a previous or other session when you select rows from a global temporary table.
There are 2 options:
Your session is not new
It's not a temporary table
Keep in mind if you use ON COMMIT PRESERVE ROWS you have to delete the rows yourself. The data is kept until the session ends.
To find out if your session is still the same, query is:
select sid,serial,logon_time from v$session
and write it to a log file.

Oracle 11g Deleting large amount of data without generating archive logs

I need to delete a large amount of data from my database on a regular basis. The process generates huge volume of archive logs. We had a database crash at one point because there was no storage space available on archive destination. How can I avoid generation of logs while I delete data?
The data to be deleted is already marked as inactive in the database. Application code ignores inactive data. I do not need the ability to rollback the operation.
I cannot partition the data in such a way that inactive data falls in one partition that can be dropped. I have to delete the data with delete statements.
I can ask DBAs to set certain configuration at table level/schema level/tablespace level/server level if needed.
I am using Oracle 11g.
What proportion of the data on the table would be deleted, what volume? Are there any referential integrity constraints to manage or is this table childless?
Depending on the answers , you might consider:
"CREATE TABLE keep_data UNRECOVERABLE AS SELECT * FROM ... WHERE
[keep condition]"
Then drop the original table
Then rename keep_table to original table
Rebuild the indexes (again with unrecoverable to prevent redo),constraints etc.
The problem with this approach is it's a multi-step DDL, process, which you will have a job to make fault tolerant and reversible.
A safer option might be to use data-pump to:
Data-pump expdp to extract the "Keep" data
TRUNCATE the table
Data-pump impdp import of data from step 1, with direct-path
At this point I suggest you read the Oracle manual on Data Pump, particularly the section on Direct Path Loads to be sure this will work for you.
MY preferred option would be partitioning.
Of course, the best way would be TenG solution (CTAS, drop and rename table) but it seems it's impossible for you.
Your only problem is the amount of archive logs and database crash problem. In this case, maybe you could partition your delete statement (for example per 10.000 rows).
Something like:
declare
e number;
i number
begin
select count(*) from myTable where [delete condition];
f :=trunc(e/10000)+1;
for i in 1.. f
loop
delete from myTable where [delete condition] and rownum<=10000;
commit;
dbms_lock.sleep(600); -- purge old archive if it's possible
end loop;
end;
After this operation, you should reorganize your table which is surely fragmented.
Alter the table to set NOLOGGING, delete the rows, then turn logging back on.

Is there something similar to commit for DDL?

When I want to update, delete, insert I need to commit. That's helpful most of the time, I might update wrong information or delete something by mistake and I can undo that.
When dropping a column, I don't need a commit. Is there something like rollback (not flashback), which enables me to undo my changes quickly? Dropping a column, even after a long analysis can probably cause damage to the table (pk, fk).
Why did Oracle provided a commit for DML but not for DDL?
Why did Oracle provided a commit for DML but not for DDL?
When you issue a DDL statement, you basically start a transaction against the Oracle data dictionary, and this transaction, to eliminate any overheads, has to be as short as possible and take effect as soon as possible. Because of this, DDL statement does double commit, before the DDL statement and then right after(or rollback, if something went wrong) the statement. This behavior makes Oracle's DDL not transactional DDL and you cannot commit or rollback it explicitly. It's just the way it is.
Having said that, if you dropped a table, then starting from 10g and up you can use flashback table technology to get it back in one statement, because Oracle, after you issue drop table statement wont drop it, it rather puts it in the recycle bin:
flashback table <<table_name>> to before drop
Unfortunately you cannot use flashback table, to restore a dropped column of a table, simply because dropped column wont be placed in the recycle bin. You will have to perform a point in time recovery of your full database or a single tablespace, or if there is a logical backup(*.dmp file), restore table from it by using imp or impdp utility.

Resources