{"id":5006,"date":"2026-01-15T12:46:51","date_gmt":"2026-01-15T07:16:51","guid":{"rendered":"https:\/\/w3buddy.com\/?p=5006"},"modified":"2026-01-20T10:13:58","modified_gmt":"2026-01-20T04:43:58","slug":"how-to-recover-truncated-table-using-flashback-in-oracle","status":"publish","type":"post","link":"https:\/\/w3buddy.com\/blog\/how-to-recover-truncated-table-using-flashback-in-oracle\/","title":{"rendered":"How to Recover Truncated Table Using Flashback in Oracle"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Truncating a table removes all data instantly, and a simple rollback cannot undo it. But if <strong>Flashback Database<\/strong> was enabled before the truncate occurred, you can restore the table to an earlier SCN or timestamp.<br>This guide includes <strong>how to check Flashback status, how to get the SCN, how to flashback, and all post-steps<\/strong>\u2014everything in one place.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Check if Flashback Is Enabled<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT flashback_on FROM v$database;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the result is <strong>YES<\/strong>, flashback recovery is possible.<br>Note: During flashback, triggers remain disabled automatically.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. How to Find the Correct SCN<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can restore the table to an SCN just before the truncate happened.<br>Here are the main ways to get the SCN.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">a. Using Alert Log (shows TRUNCATE time \u2192 convert to SCN)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Find the timestamp of TRUNCATE in alert log, then get SCN from that timestamp:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT TIMESTAMP_TO_SCN(TO_TIMESTAMP('2024-04-15 19:00:00',\n       'YYYY-MM-DD HH24:MI:SS')) AS scn_value\nFROM dual;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">b. Get current SCN at any time<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Useful if you know the truncate happened shortly before:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT current_scn FROM v$database;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">c. Use Flashback Query to inspect history<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If table history exists:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT versions_startscn, versions_endscn\nFROM TEST VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This gives you the SCN range where data existed before truncate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">d. Convert timestamp to SCN directly<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you know the exact time when truncate happened:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT TIMESTAMP_TO_SCN(TO_TIMESTAMP('2024-04-15 19:00:00',\n       'YYYY-MM-DD HH24:MI:SS')) AS scn_value\nFROM dual;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">e. Convert SCN to timestamp (reverse check)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT SCN_TO_TIMESTAMP(&lt;scn_number>) FROM dual;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Flashback Steps<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">a. Enable Row Movement<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE TEST ENABLE ROW MOVEMENT;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">b. Flashback the table using SCN<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>FLASHBACK TABLE TEST TO SCN &lt;scn_number>;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">or flashback using timestamp<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>FLASHBACK TABLE TEST TO TIMESTAMP TO_TIMESTAMP(\n       '2024-04-15 19:00:00',\n       'YYYY-MM-DD HH24:MI:SS');<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. Post-Recovery Steps<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Verify recovered rows<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT COUNT(*) FROM TEST;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Disable row movement again<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE TEST DISABLE ROW MOVEMENT;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Check and recompile invalid dependent objects<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check invalid:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT object_name, status\nFROM user_objects\nWHERE object_type IN ('VIEW','TRIGGER')\nAND status &lt;> 'VALID';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Recompile:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER VIEW my_view COMPILE;\nALTER TRIGGER my_trigger COMPILE;\nALTER PROCEDURE my_procedure COMPILE;\nALTER FUNCTION my_function COMPILE;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5. Summary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To recover a truncated table using Flashback in Oracle:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Ensure Flashback is enabled.<\/li>\n\n\n\n<li>Get the SCN (using alert log time, flashback query, timestamp conversion, or current SCN).<\/li>\n\n\n\n<li>Enable row movement.<\/li>\n\n\n\n<li>Flashback to SCN or timestamp.<\/li>\n\n\n\n<li>Verify data and recompile objects.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Truncating a table removes all data instantly, and a simple rollback cannot undo it. But if Flashback Database was enabled before the truncate occurred, you can restore the table to an earlier SCN or timestamp.This guide includes how to check Flashback status, how to get the SCN, how to flashback, and all post-steps\u2014everything in one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5008,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowu461DA:productID":"","footnotes":""},"categories":[1225],"tags":[],"class_list":["post-5006","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/5006","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/comments?post=5006"}],"version-history":[{"count":1,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/5006\/revisions"}],"predecessor-version":[{"id":5007,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/5006\/revisions\/5007"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media\/5008"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=5006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=5006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/tags?post=5006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}