{"id":6620,"date":"2016-01-02T20:05:09","date_gmt":"2016-01-02T19:05:09","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/"},"modified":"2016-01-02T20:05:09","modified_gmt":"2016-01-02T19:05:09","slug":"flashback-table-after-multiple-drop","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/","title":{"rendered":"Flashback table after multiple drop"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nFLASHBACK TABLE restores the latest version that is available in recycle bin. If you did multiple drop \/ create you may want to restore oldest versions. Of course it&#8217;s <a href=\"https:\/\/docs.oracle.com\/database\/121\/SQLRF\/statements_9012.htm#SQLRF55003\" target=\"_blank\" rel=\"noopener noreferrer\">documented<\/a> &#8211; everything is in the doc. But an example may be useful to understand it before you need it.<br \/>\n<!--more--><br \/>\nLet&#8217;s create and drop several times the DEMO table. I change the column name so that I can check easily which one has been restored<\/p>\n<pre><code>\n20:03:10 SQL&gt; create table DEMO(id number constraint DEMOPK primary key , C1 char );\nTable created.\n20:03:12 SQL&gt; drop table DEMO;\nTable dropped.\n20:03:12 SQL&gt; create table DEMO(id number constraint DEMOPK primary key , C2 char );\nTable created.\n20:03:14 SQL&gt; drop table DEMO;\nTable dropped.\n20:03:14 SQL&gt; create table DEMO(id number constraint DEMOPK primary key , C3 char );\nTable created.\n20:03:16 SQL&gt; drop table DEMO;\nTable dropped.\n20:03:16 SQL&gt; create table DEMO(id number constraint DEMOPK primary key , C4 char );\nTable created.\n20:03:18 SQL&gt; drop table DEMO;\nTable dropped.\n20:03:18 SQL&gt; create table DEMO(id number constraint DEMOPK primary key , C5 char );\nTable created.\n20:03:20 SQL&gt; drop table DEMO;\nTable dropped.\n20:03:20 SQL&gt; create table DEMO(id number constraint DEMOPK primary key , C6 char );\nTable created.\n20:03:22 SQL&gt; drop table DEMO;\nTable dropped.\n<\/code><\/pre>\n<p>Here is what I have in recycle bin<\/p>\n<pre><code>\n20:03:22 SQL&gt; select object_name,original_name,type,dropscn,createtime,droptime from user_recyclebin order by dropscn;\n&nbsp;\nOBJECT_NAME                    ORIGINAL_N TYPE          DROPSCN CREATETIME          DROPTIME\n------------------------------ ---------- ---------- ---------- ------------------- -------------------\nBIN$KF+J+xYlFjngU3VOqMB9Kw==$0 DEMOPK     INDEX         4350801 2016-01-02:20:03:10 2016-01-02:20:03:12\nBIN$KF+J+xYmFjngU3VOqMB9Kw==$0 DEMO       TABLE         4350804 2016-01-02:20:03:10 2016-01-02:20:03:12\nBIN$KF+J+xYoFjngU3VOqMB9Kw==$0 DEMOPK     INDEX         4350830 2016-01-02:20:03:12 2016-01-02:20:03:14\nBIN$KF+J+xYpFjngU3VOqMB9Kw==$0 DEMO       TABLE         4350833 2016-01-02:20:03:12 2016-01-02:20:03:14\nBIN$KF+J+xYrFjngU3VOqMB9Kw==$0 DEMOPK     INDEX         4350857 2016-01-02:20:03:14 2016-01-02:20:03:16\nBIN$KF+J+xYsFjngU3VOqMB9Kw==$0 DEMO       TABLE         4350861 2016-01-02:20:03:14 2016-01-02:20:03:16\nBIN$KF+J+xYuFjngU3VOqMB9Kw==$0 DEMOPK     INDEX         4350885 2016-01-02:20:03:16 2016-01-02:20:03:18\nBIN$KF+J+xYvFjngU3VOqMB9Kw==$0 DEMO       TABLE         4350889 2016-01-02:20:03:16 2016-01-02:20:03:18\nBIN$KF+J+xYxFjngU3VOqMB9Kw==$0 DEMOPK     INDEX         4350912 2016-01-02:20:03:18 2016-01-02:20:03:20\nBIN$KF+J+xYyFjngU3VOqMB9Kw==$0 DEMO       TABLE         4350915 2016-01-02:20:03:18 2016-01-02:20:03:20\nBIN$KF+J+xY0FjngU3VOqMB9Kw==$0 DEMOPK     INDEX         4350939 2016-01-02:20:03:20 2016-01-02:20:03:22\nBIN$KF+J+xY1FjngU3VOqMB9Kw==$0 DEMO       TABLE         4350943 2016-01-02:20:03:20 2016-01-02:20:03:22\n&nbsp;\n12 rows selected.\n<\/code><\/pre>\n<p>and my goal now is to restore a previous version.<\/p>\n<h3>issue flashback multiple times<\/h3>\n<p>So the documentation tells to issue multiple flashback commands:<\/p>\n<pre><code>\n20:03:22 SQL&gt; flashback table DEMO to before drop;\nFlashback complete.\n&nbsp;\n20:03:22 SQL&gt; desc DEMO;\n Name           Null?    Type\n -------------- -------- --------\n ID             NOT NULL NUMBER\n C6                      CHAR(1)\n<\/code><\/pre>\n<p>that&#8217;s the latest version. Let&#8217;s issue the command again:<\/p>\n<pre><code>\n20:03:22 SQL&gt; flashback table DEMO to before drop;\nflashback table DEMO to before drop\n*\nERROR at line 1:\nORA-38312: original name is used by an existing object\n<\/code><\/pre>\n<p>Yes of course, I have to drop it before.<\/p>\n<pre><code>\n20:03:22 SQL&gt; drop table DEMO;\nTable dropped.\n&nbsp;\n20:03:22 SQL&gt; flashback table DEMO to before drop;\nFlashback complete.\n&nbsp;\n20:03:22 SQL&gt; desc DEMO;\n Name           Null?    Type\n -------------- -------- --------\n ID             NOT NULL NUMBER\n C6                      CHAR(1)\n<\/code><\/pre>\n<p>Ok, as I dropped it just before, that the latest version that is restored&#8230;<\/p>\n<h3>purge<\/h3>\n<p>If I want to issue multiple flashback table commands, I have to drop purge so that the intermediate restored tables don&#8217;t go to recycle bin<\/p>\n<pre><code>\n20:03:22 SQL&gt; drop table DEMO purge;\nTable dropped.\n&nbsp;\n20:03:23 SQL&gt; flashback table DEMO to before drop;\nFlashback complete.\n&nbsp;\n20:03:23 SQL&gt; desc DEMO;\n Name           Null?    Type\n -------------- -------- --------\n ID             NOT NULL NUMBER\n C5                      CHAR(1)\n<\/code><\/pre>\n<p>that&#8217;s fine: I restored the N-1 version.<\/p>\n<h3>rename<\/h3>\n<p>The other solution is to restore it to another table, dropping that other table, or changing name each time:<\/p>\n<pre><code>\n20:03:23 SQL&gt; flashback table DEMO to before drop rename to DEMO1;\nFlashback complete.\n&nbsp;\n20:03:23 SQL&gt; desc DEMO1;\n Name           Null?    Type\n -------------- -------- --------\n ID             NOT NULL NUMBER\n C4                      CHAR(1)\n&nbsp;\n20:03:23 SQL&gt; flashback table DEMO to before drop rename to DEMO2;\nFlashback complete.\n&nbsp;\n20:03:23 SQL&gt; desc DEMO2;\n Name           Null?    Type\n -------------- -------- --------\n ID             NOT NULL NUMBER\n C3                      CHAR(1)\n<\/code><\/pre>\n<p>Here I rewind two older versions.<\/p>\n<h3>name the recycle bin object<\/h3>\n<p>But there is a direct possibility if you know the version you want from the DBA_RECYCLEBIN view.<\/p>\n<pre><code>\n20:03:23 SQL&gt; desc \"BIN$KF+J+xYpFjngU3VOqMB9Kw==$0\"\n Name           Null?    Type\n -------------- -------- --------\n ID             NOT NULL NUMBER\n C2                      CHAR(1)\n<\/code><\/pre>\n<p>And I restore that directly to a new table:<\/p>\n<pre><code>\n20:03:23 SQL&gt; flashback table \"BIN$KF+J+xYpFjngU3VOqMB9Kw==$0\" to before drop rename to DEMO3;\nFlashback complete.\n<\/code><\/pre>\n<p>So that&#8217;s probably the fastest way to restore an old version.<\/p>\n<p>All that is possible because each time we flashback to before drop, the restored version is removed from the recycle bin.<br \/>\nFrom my example, only one remains here:<\/p>\n<pre><code>\n20:03:24 SQL&gt; select object_name,original_name,type,dropscn,createtime,droptime from user_recyclebin order by dropscn;\n&nbsp;\nOBJECT_NAME                    ORIGINAL_N TYPE          DROPSCN CREATETIME          DROPTIME\n------------------------------ ---------- ---------- ---------- ------------------- -------------------\nBIN$KF+J+xYlFjngU3VOqMB9Kw==$0 DEMOPK     INDEX         4350801 2016-01-02:20:03:10 2016-01-02:20:03:12\nBIN$KF+J+xYmFjngU3VOqMB9Kw==$0 DEMO       TABLE         4350804 2016-01-02:20:03:10 2016-01-02:20:03:12\n<\/code><\/pre>\n<p>so the safest way is probably to flashback to a different table name each time, and clean that only when you&#8217;re sure you don&#8217;t need them anymore.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . FLASHBACK TABLE restores the latest version that is available in recycle bin. If you did multiple drop \/ create you may want to restore oldest versions. Of course it&#8217;s documented &#8211; everything is in the doc. But an example may be useful to understand it before you need it.<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[96],"type_dbi":[],"class_list":["post-6620","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","tag-oracle"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Flashback table after multiple drop - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flashback table after multiple drop\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . FLASHBACK TABLE restores the latest version that is available in recycle bin. If you did multiple drop \/ create you may want to restore oldest versions. Of course it&#8217;s documented &#8211; everything is in the doc. But an example may be useful to understand it before you need it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-02T19:05:09+00:00\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Flashback table after multiple drop\",\"datePublished\":\"2016-01-02T19:05:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/\"},\"wordCount\":310,\"commentCount\":0,\"keywords\":[\"Oracle\"],\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/\",\"name\":\"Flashback table after multiple drop - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2016-01-02T19:05:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Flashback table after multiple drop\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Flashback table after multiple drop - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/","og_locale":"en_US","og_type":"article","og_title":"Flashback table after multiple drop","og_description":"By Franck Pachot . FLASHBACK TABLE restores the latest version that is available in recycle bin. If you did multiple drop \/ create you may want to restore oldest versions. Of course it&#8217;s documented &#8211; everything is in the doc. But an example may be useful to understand it before you need it.","og_url":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/","og_site_name":"dbi Blog","article_published_time":"2016-01-02T19:05:09+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Flashback table after multiple drop","datePublished":"2016-01-02T19:05:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/"},"wordCount":310,"commentCount":0,"keywords":["Oracle"],"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/","url":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/","name":"Flashback table after multiple drop - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2016-01-02T19:05:09+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/flashback-table-after-multiple-drop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Flashback table after multiple drop"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/6620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=6620"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/6620\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=6620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=6620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=6620"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=6620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}