<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3984838021726720828</id><updated>2012-02-16T03:25:10.791-08:00</updated><title type='text'>Oracle Dvelopment 11i</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://oracledev11i.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3984838021726720828/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://oracledev11i.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Andre Rusanoff</name><uri>http://www.blogger.com/profile/03130035350264451766</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3984838021726720828.post-6997875339744359319</id><published>2009-05-18T17:07:00.001-07:00</published><updated>2009-05-22T12:30:09.869-07:00</updated><title type='text'>Generate PL/SQL code using BULK COLLECT FORALL statements</title><content type='html'>&lt;span xmlns=''&gt;&lt;p&gt;Combination of BULK COLLECT and FORALL statements is used primarily to improve the performance of ETL processes that deal with large volumes of data and also to avoid &lt;span style='font-family:Arial; font-size:10pt'&gt;ORA-01555 Snapshot&lt;strong&gt;&lt;br /&gt;					&lt;/strong&gt;Too Old&lt;/span&gt; error when periodic commits are necessary during updating/inserting the rows in the same table that is used in the select statement fetching the source data. The performance is greatly enhanced by the fact that the switches between SQL to PL/SQL engines are not performed at each raw, but only once for the entire DML statement for the number of rows fetched specified by the LIMIT clause of the BULK COLLECT statement. Further performance enhancements can be achieved by additional utilization of multithreading and partitioning of target table.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Coding the PL/SQL procedure that uses BULK COLLECT FORALL statements can be rather time consuming and error prone effort when you need to create the code accommodating a table with large number of columns and you need to create a separate collection for each column of such large table.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;This script offers a quick solution to automatically generate the PL/SQL code (template) that uses Data Dictionary to create all necessary types, collections as well as basic code to select, fetch, and then insert the fetched data into a target table using FORALL statement. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;When the script is executed, it prompts you to provide the TABLE_NAME. This version of the script uses USER_TABLES data dictionary table to retrieve the column information. It can be easily expended to use DBA_TABLES as well; however you would then need to provide the table owner parameter value.   &lt;br /&gt;&lt;/p&gt;&lt;p&gt;This is how the script works:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;It uses the table name provided by user to generate:&lt;br /&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;All types and collections (for each column in the table) in the Declaration section of PL/SQL block.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Definition of CURSOR to select all data from specified table.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;BULK COLLECT loop iteration to fetch 20000 rows at the time.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Dummy Transform section.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;FORALL statement to insert transformed data into a target table (a pseudo table name).  &lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The script creates a template using a pseudo name for the target table by taking first 25 characters of the source table name and then attaching a '_bkup' suffix to it. It also assumes that you need to insert the data into empty table; therefore there is a TRUNCATE TABLE statement in the beginning of the execution logic.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;When used for ETL processing, the "T" (transform) portion of the code logic must be added to the code in-between FETCH and FORALL statements.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Just run this script in SQL*Plus and it will create a spool file with your table_name appended with '_proc' suffix containing the PL/SQL Procedure code.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;define tab=&amp;amp;table_name&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SET lines 200&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SET feed OFF&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SET ver OFF&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SET pages 0&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;COLUMN last_col new_value last_column&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT MAX(column_id) last_col&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tab_columns&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab');&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;spool &amp;amp;tab._proc.SQL&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT 'CREATE OR REPLACE PROCEDURE dmt_load'||SUBSTR(LOWER('&amp;amp;tab'),1,22)||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;        'IS'||CHR(10)&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tables&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab');&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT '   TYPE '||INITCAP(SUBSTR(column_name,1,23))||'TabType is TABLE OF '||LOWER(table_name)||'.'||LOWER(column_name)||'%TYPE;'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '   '||INITCAP(SUBSTR(column_name,1,23))||'Tab '||INITCAP(SUBSTR(column_name,1,23))||'TabType;'&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tab_columns&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab')&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; ORDER BY&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       column_id;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SET recsep OFF&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT DECODE(column_id,1,'   CURSOR '||SUBSTR(LOWER(table_name),1,28)||'_c'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '   IS'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '      SELECT '||LOWER(column_name),'            ,'||LOWER(column_name))&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tab_columns&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab')&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; ORDER BY&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       column_id;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT '        FROM '||LOWER(table_name)||';'&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tables&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab');&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SET recsep wr&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '   BEGIN'||CHR(10)||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '      EXECUTE IMMEDIATE '||''''||'TRUNCATE TABLE '||SUBSTR(LOWER('&amp;amp;tab'),1,25)||'_bkup'||''';'||CHR(10)||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '      OPEN '||SUBSTR(LOWER('&amp;amp;tab'),1,28)||'_c;'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '      LOOP'&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM dual;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SET recsep OFF&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT DECODE(column_id,1,'         FETCH '||SUBSTR(LOWER('&amp;amp;tab'),1,28)||'_c'||' BULK COLLECT INTO '||INITCAP(SUBSTR(column_name,1,23))||'Tab '&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;                      ,'                                   ,'||INITCAP(SUBSTR(column_name,1,23))||'Tab ')&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tab_columns&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab')&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; ORDER BY&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       column_id;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT '         LIMIT 20000;'&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM dual;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '         /*'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '         ||'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '         || Insert your data transformation logic here'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '         ||'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '         */'&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM dual;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '         FORALL i IN 1 .. '||INITCAP(SUBSTR(column_name,1,23))||'Tab.COUNT'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '            INSERT INTO '||LOWER(table_name)||'_bkup'&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tab_columns&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab')&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;   AND ROWNUM &amp;lt; 2;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT DECODE(column_id,1,'                       ('||LOWER(column_name)&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;                      ,'                       ,'||LOWER(column_name))&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tab_columns&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab')&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; ORDER BY&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       column_id;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT '                       )'&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM dual;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT DECODE(column_id,1,'                VALUES ('||INITCAP(SUBSTR(column_name,1,23))||'Tab '||'(i)'&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;                      ,'                       ,'||INITCAP(SUBSTR(column_name,1,23))||'Tab '||'(i)')&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tab_columns&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab')&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; ORDER BY&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       column_id;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT '                       );'&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM dual;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SET recsep wr&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;SELECT '         COMMIT;'||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       CHR(10)||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '         IF '||SUBSTR(LOWER('&amp;amp;tab'),1,28)||'_c'||'%NOTFOUND THEN'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '            EXIT;'||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '         END IF;'||CHR(10)||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '      END LOOP;'||CHR(10)||CHR(10)||&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;       '   END dmt_load'||SUBSTR(LOWER('&amp;amp;tab'),1,22)||';'||CHR(10)&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;  FROM user_tables&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt; WHERE table_name=UPPER('&amp;amp;tab');&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style='font-size:8pt'&gt;&lt;strong&gt;spool OFF&lt;/strong&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3984838021726720828-6997875339744359319?l=oracledev11i.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracledev11i.blogspot.com/feeds/6997875339744359319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://oracledev11i.blogspot.com/2009/05/generate-plsql-code-using-bulk-collect.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3984838021726720828/posts/default/6997875339744359319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3984838021726720828/posts/default/6997875339744359319'/><link rel='alternate' type='text/html' href='http://oracledev11i.blogspot.com/2009/05/generate-plsql-code-using-bulk-collect.html' title='Generate PL/SQL code using BULK COLLECT FORALL statements'/><author><name>Andre Rusanoff</name><uri>http://www.blogger.com/profile/03130035350264451766</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
