{"id":81,"date":"2009-12-31T16:16:51","date_gmt":"2009-12-31T23:16:51","guid":{"rendered":"http:\/\/journeyman.ivystreetinc.com\/?p=81"},"modified":"2009-12-31T19:09:06","modified_gmt":"2010-01-01T02:09:06","slug":"oracle-batch-commits","status":"publish","type":"post","link":"http:\/\/10kdev.net\/?p=81","title":{"rendered":"ORACLE: Batch Commits"},"content":{"rendered":"<p>I had to write an Oracle script template for work to kind of create a guideline for our developers since we are getting inputs from ourselves, DBA standards, and business requirements from our BA&#8217;s and customers.<\/p>\n<p>Anyway, one thing they wanted was batch commits . . . so I wrote this quick little piece:<\/p>\n<p>It creates a temp table, populates it, and puts a DBMS_OUTPUT line for whatever number I set the commit at . . . pretty self explanatory.<\/p>\n<p><span style=\"color: #333399;\">CREATE\u00a0\u00a0 GLOBAL\u00a0 TEMPORARY TABLE temp_Cursor_Count\u00a0 (<br \/>\ntestNumber Number(10)<br \/>\n) ON COMMIT PRESERVE ROWS;<br \/>\ncommit;<\/span><\/p>\n<p><span style=\"color: #333399;\">DECLARE<\/span><\/p>\n<p><span style=\"color: #333399;\">curVariable Number;<\/span><\/p>\n<p><span style=\"color: #333399;\">cursorCount Number(10) := 0;<br \/>\ncursorCommit Number(10) := 1000;<br \/>\ncursorMod Number(10) := 1;<\/span><\/p>\n<p><span style=\"color: #333399;\">CURSOR tt is<br \/>\nselect * from temp_Cursor_Count;<\/span><\/p>\n<p><span style=\"color: #333399;\">begin<\/span><\/p>\n<p><span style=\"color: #333399;\">&#8211;populate temp table<br \/>\nFor i in 1..9999<br \/>\nLoop<br \/>\ninsert into temp_Cursor_Count(testNumber) values (i);<br \/>\nend loop;<br \/>\ncommit;<\/span><\/p>\n<p><span style=\"color: #333399;\">FOR record_tt IN tt LOOP<br \/>\n&#8211;INITIALIZE Cursor values<br \/>\ncurVariable\u00a0\u00a0\u00a0\u00a0\u00a0 :=record_tt.testNumber;<\/span><\/p>\n<p><span style=\"color: #333399;\">cursorCount := cursorCount + 1;<\/span><\/p>\n<p><span style=\"color: #333399;\">select MOD(cursorCount,cursorCommit) into cursorMod from dual;<\/span><\/p>\n<p><span style=\"color: #333399;\">if cursorMod=0 then<br \/>\n&#8211;Normally this is where your COMMIT would occur.<br \/>\nDBMS_OUTPUT.PUT_LINE(cursorCount);<br \/>\nend if;<\/span><\/p>\n<p><span style=\"color: #333399;\">END LOOP;<br \/>\nend;<\/span><\/p>\n<p><span style=\"color: #333399;\">truncate table temp_Cursor_Count;<br \/>\ncommit;<br \/>\ndrop table temp_Cursor_Count;<br \/>\ncommit;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had to write an Oracle script template for work to kind of create a guideline for our developers since we are getting inputs from ourselves, DBA standards, and business requirements from our BA&#8217;s and customers. Anyway, one thing they wanted was batch commits . . . so I wrote this quick little piece: It [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/81"}],"collection":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":8,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":83,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions\/83"}],"wp:attachment":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}