{"id":25,"date":"2012-03-08T15:27:00","date_gmt":"2012-03-08T15:27:00","guid":{"rendered":"http:\/\/anjo.pt\/wp\/keyword-oracle\/2012\/03\/08\/ora-14450-global-temporary-tables-and-on-commit-preserve-rows\/"},"modified":"2015-11-17T20:27:24","modified_gmt":"2015-11-17T19:27:24","slug":"ora-14450-global-temporary-tables-and-on-commit-preserve-rows","status":"publish","type":"post","link":"https:\/\/anjo.pt\/keyword-oracle\/2012\/03\/08\/ora-14450-global-temporary-tables-and-on-commit-preserve-rows\/","title":{"rendered":"ORA-14450, Global temporary tables and on commit preserve rows"},"content":{"rendered":"<p>&#8212; Clean environment<br \/>&nbsp;drop table gtt;<br \/>&nbsp;drop table gtt<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *<br \/>ERROR at line 1:<br \/>ORA-00942: table or view does not exist<\/p>\n<p>&#8212; Global temporary &#8211; preserve rows<br \/>create global temporary table gtt ( x int ) on commit preserve rows;<br \/>Table created.<\/p>\n<p>&#8212; Keeps information until the end of the user session<br \/>select duration from user_tables where table_name = &#8216;GTT&#8217;;<br \/>DURATION<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>SYS$SESSION<\/p>\n<p>&#8212; Insert one row <br \/>insert into gtt values(1);<br \/>1 row created.<\/p>\n<p>&#8212; Creates a TO lock<br \/>select sid, type, id1, id2, lmode from v$lock where id1=(select object_id from all_objects where object_name=&#8217;GTT&#8217;);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SID TY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LMODE<br \/>&#8212;&#8212;&#8212;- &#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4343 TO&nbsp;&nbsp;&nbsp;&nbsp; 403115&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<\/p>\n<p>&#8212; Commit transaction<br \/>commit;<br \/>Commit complete.<\/p>\n<p>&#8212; TO lock continues&#8230; <br \/>select sid, type, id1, id2, lmode from v$lock where id1=(select object_id from all_objects where object_name=&#8217;GTT&#8217;);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SID TY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LMODE<br \/>&#8212;&#8212;&#8212;- &#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4343 TO&nbsp;&nbsp;&nbsp;&nbsp; 403115&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<\/p>\n<p>&#8212; Any user that tries to change the table<br \/>&#8212; Will receive: ORA-14450: attempt to access a transactional temp table already in use<br \/>alter table gtt add (y int);<br \/>alter table gtt add (y int)<br \/>*<br \/>ERROR at line 1:<br \/>ORA-14450: attempt to access a transactional temp table already in use<\/p>\n<p>&#8212; Only after doing truncate<br \/>truncate table gtt;<br \/>Table truncated.<\/p>\n<p>&#8212; TO lock disappears <br \/>select * from v$lock where id1=(select object_id from all_objects where object_name=&#8217;GTT&#8217;);<br \/>no rows selected<\/p>\n<p>&#8212; With a global temporary table delete rows<br \/>drop table gtt;<br \/>Table dropped.<\/p>\n<p>create global temporary table gtt ( x int ) on commit delete rows;<br \/>Table created.<\/p>\n<p>&#8212; The duration is at transaction level<br \/>select duration from user_tables where table_name = &#8216;GTT&#8217;;<br \/>DURATION<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>SYS$TRANSACTION<\/p>\n<p>&#8212; Insert one row <br \/>insert into gtt values(1);<br \/>1 row created.<\/p>\n<p>&#8212; Creates a TO lock<br \/>select sid, type, id1, id2, lmode from v$lock where id1=(select object_id from all_objects where object_name=&#8217;GTT&#8217;);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SID TY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LMODE<br \/>&#8212;&#8212;&#8212;- &#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4343 TO&nbsp;&nbsp;&nbsp;&nbsp; 403116&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<\/p>\n<p>&#8212; That disappears as soon as you commit the transaction<br \/>commit;<br \/>Commit complete.<\/p>\n<p>select sid, type, id1, id2, lmode from v$lock where id1=(select object_id from all_objects where object_name=&#8217;GTT&#8217;);<br \/>no rows selected<\/p>\n<p>&#8212; Clean up environment<br \/>drop table gtt;<br \/>Table dropped.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212; Clean environment&nbsp;drop table gtt;&nbsp;drop table gtt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *ERROR at line 1:ORA-00942: table or view does not exist &#8212; Global temporary &#8211; preserve rowscreate global temporary table gtt ( x int ) on commit preserve rows;Table created. &#8212; Keeps information until the end of the user sessionselect duration from user_tables where table_name = &#8216;GTT&#8217;;DURATION&#8212;&#8212;&#8212;&#8212;&#8212;SYS$SESSION &#8212; Insert [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","category-oracle","czr-hentry"],"_links":{"self":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":1,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":169,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/25\/revisions\/169"}],"wp:attachment":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}