<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: PL/SQL Associative Arrays</title>
	<atom:link href="http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/feed/" rel="self" type="application/rss+xml" />
	<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/</link>
	<description>Technology with a focus on Oracle, Application Express and Linux</description>
	<lastBuildDate>Fri, 13 Nov 2009 11:47:58 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Gary</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1476</link>
		<dc:creator>Gary</dc:creator>
		<pubDate>Thu, 14 Aug 2008 23:06:50 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1476</guid>
		<description>If you don&#039;t know the number of columns you are going to update (and hence the number of bind variables you need to use), then you&#039;ll need to use DBMS_SQL, not execute immediate.
It will go something like this
Loop through the array generating the SQL
dbms_sql.Parse the generated SQL
Loop through the array a second time, to DBMS_SQL.BIND_VARIABLE each variable
Finally DBMS_SQL.EXECUTE the sql.</description>
		<content:encoded><![CDATA[<p>If you don&#8217;t know the number of columns you are going to update (and hence the number of bind variables you need to use), then you&#8217;ll need to use DBMS_SQL, not execute immediate.<br />
It will go something like this<br />
Loop through the array generating the SQL<br />
dbms_sql.Parse the generated SQL<br />
Loop through the array a second time, to DBMS_SQL.BIND_VARIABLE each variable<br />
Finally DBMS_SQL.EXECUTE the sql.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DJ</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1475</link>
		<dc:creator>DJ</dc:creator>
		<pubDate>Thu, 14 Aug 2008 16:56:39 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1475</guid>
		<description>I&#039;m trying to use an associative array to perform dynamic sql.  
I&#039;m looking to use bind variables, but I don&#039;t know if this is possible using associative arrays.  
Please see the simplified example below. 
What I am looking for is something for the vColumnUpdate line that would parse this using the associative array record as bind variable.  I know this does not work, just there as an example of what I would like to accomplish.  
Is there a way to tell oracle to prepare a variable string as though you were executing a dynamic sql statement.  For example --&gt; execute immediate &#039;select :x from dual&#039; using 1.

declare
    type assoc_arr is table of varchar2(255) index by pls_integer;
    db_col assoc_arr;
	field_val assoc_arr;
	vUpdateStatement varchar2(4000);
	vColumnUpdate	varchar2(4000);
	vWhereClause	varchar2(4000);
begin
	db_col(0) := &#039;ENAME&#039;;
	db_col(1) := &#039;JOB&#039;;
	
	field_val(0) := &#039;1&#039;;
	field_val(1) := &#039;2&#039;;
    
	vUpdateStatement := &#039; update emp set&#039;;
	vWhereClause := &#039; where empno = 9000&#039;;
	
	for i IN db_col.FIRST .. db_col.LAST
    loop
        vColumnUpdate := db_col(i) &#124;&#124; &#039; = :mybindvar ,&#039; using field_val(i);
        vUpdateStatement := vUpdateStatement &#124;&#124; vColumnUpdate; 
    end loop;

    --Remove the last comma
	vUpdateStatement := substr(vUpdateStatement, 1, instr(vUpdateStatement,&#039;,&#039;,-1) -1);
  
	execute immediate (vUpdateStatement &#124;&#124; vWhereClause);
    
end;
/</description>
		<content:encoded><![CDATA[<p>I&#8217;m trying to use an associative array to perform dynamic sql.<br />
I&#8217;m looking to use bind variables, but I don&#8217;t know if this is possible using associative arrays.<br />
Please see the simplified example below.<br />
What I am looking for is something for the vColumnUpdate line that would parse this using the associative array record as bind variable.  I know this does not work, just there as an example of what I would like to accomplish.<br />
Is there a way to tell oracle to prepare a variable string as though you were executing a dynamic sql statement.  For example &#8211;&gt; execute immediate &#8217;select <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' />  from dual&#8217; using 1.</p>
<p>declare<br />
    type assoc_arr is table of varchar2(255) index by pls_integer;<br />
    db_col assoc_arr;<br />
	field_val assoc_arr;<br />
	vUpdateStatement varchar2(4000);<br />
	vColumnUpdate	varchar2(4000);<br />
	vWhereClause	varchar2(4000);<br />
begin<br />
	db_col(0) := &#8216;ENAME&#8217;;<br />
	db_col(1) := &#8216;JOB&#8217;;</p>
<p>	field_val(0) := &#8216;1&#8242;;<br />
	field_val(1) := &#8216;2&#8242;;</p>
<p>	vUpdateStatement := &#8216; update emp set&#8217;;<br />
	vWhereClause := &#8216; where empno = 9000&#8242;;</p>
<p>	for i IN db_col.FIRST .. db_col.LAST<br />
    loop<br />
        vColumnUpdate := db_col(i) || &#8216; = :mybindvar ,&#8217; using field_val(i);<br />
        vUpdateStatement := vUpdateStatement || vColumnUpdate;<br />
    end loop;</p>
<p>    &#8211;Remove the last comma<br />
	vUpdateStatement := substr(vUpdateStatement, 1, instr(vUpdateStatement,&#8217;,',-1) -1);</p>
<p>	execute immediate (vUpdateStatement || vWhereClause);</p>
<p>end;<br />
/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephane</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1312</link>
		<dc:creator>Stephane</dc:creator>
		<pubDate>Thu, 10 Apr 2008 20:21:49 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1312</guid>
		<description>I used them to implement string translation module for my PL/SQL application. A table stores all my translatable strings. I create an array based on my table record type, indexed by a text column in the table.

I populate the array in the package init section of my package... mind you this stores the array, I believe in the PGA? So as mentioned, keep it fairly small...

Works great! I simply reference my various text labels in the application with a call to pkg_gui_text.translate(&#039;welcome&#039;)... and based on current application context for the session, it&#039;ll return in proper language...</description>
		<content:encoded><![CDATA[<p>I used them to implement string translation module for my PL/SQL application. A table stores all my translatable strings. I create an array based on my table record type, indexed by a text column in the table.</p>
<p>I populate the array in the package init section of my package&#8230; mind you this stores the array, I believe in the PGA? So as mentioned, keep it fairly small&#8230;</p>
<p>Works great! I simply reference my various text labels in the application with a call to pkg_gui_text.translate(&#8216;welcome&#8217;)&#8230; and based on current application context for the session, it&#8217;ll return in proper language&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Log Buffer #86: a Carnival of the Vanities for DBAs</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1261</link>
		<dc:creator>Log Buffer #86: a Carnival of the Vanities for DBAs</dc:creator>
		<pubDate>Fri, 29 Feb 2008 23:23:41 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1261</guid>
		<description>[...] another illuminating discussion on Tyler Muth&#8217;s blog, this one on PL/SQL associative arrays. &#8220;They’re particularly useful for name-value pair type arrays where you want to look up the [...]</description>
		<content:encoded><![CDATA[<p>[...] another illuminating discussion on Tyler Muth&#8217;s blog, this one on PL/SQL associative arrays. &#8220;They’re particularly useful for name-value pair type arrays where you want to look up the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dinesh Bhat</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1259</link>
		<dc:creator>Dinesh Bhat</dc:creator>
		<pubDate>Wed, 27 Feb 2008 01:55:29 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1259</guid>
		<description>A nice article. 
I tend to store all my metadata, however small it is in tables. This way it is (in my opinion) slightly easier to change and update and I would assume that Oracle would cache it if used often possibilities for extension. I have never used associative arrays and I would like to know if there are any adverse effects to exclusively storing metadata in tables and looking it up in PL/SQL.</description>
		<content:encoded><![CDATA[<p>A nice article.<br />
I tend to store all my metadata, however small it is in tables. This way it is (in my opinion) slightly easier to change and update and I would assume that Oracle would cache it if used often possibilities for extension. I have never used associative arrays and I would like to know if there are any adverse effects to exclusively storing metadata in tables and looking it up in PL/SQL.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sival</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1258</link>
		<dc:creator>sival</dc:creator>
		<pubDate>Tue, 26 Feb 2008 18:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1258</guid>
		<description>Hi Tyler,

I like your blog you provide some very useful comments in a concise manner. Thanks.

We&#039;re using both types of collections (indexed by integer and varchar2). They help a lot in processing arrays of information. I find them much more flexible and easy to use than varrays or SQL table types. Their syntax is more intuitive. I only wish that PL/SQL custom types have some object-oriented features.

One example where we use collections indexed by varchar2 is to store our custom error messages. You can reference them by name. So they are very easy to access, understandable from a programmer&#039;s point of view and the custom messages is only stored once. It makes our error messages more consistent.

sival
letstalkaboutoracle.wordpress.com</description>
		<content:encoded><![CDATA[<p>Hi Tyler,</p>
<p>I like your blog you provide some very useful comments in a concise manner. Thanks.</p>
<p>We&#8217;re using both types of collections (indexed by integer and varchar2). They help a lot in processing arrays of information. I find them much more flexible and easy to use than varrays or SQL table types. Their syntax is more intuitive. I only wish that PL/SQL custom types have some object-oriented features.</p>
<p>One example where we use collections indexed by varchar2 is to store our custom error messages. You can reference them by name. So they are very easy to access, understandable from a programmer&#8217;s point of view and the custom messages is only stored once. It makes our error messages more consistent.</p>
<p>sival<br />
letstalkaboutoracle.wordpress.com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marco</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1254</link>
		<dc:creator>Marco</dc:creator>
		<pubDate>Mon, 25 Feb 2008 21:39:54 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1254</guid>
		<description>Great topic, Tyler.  We&#039;re using associative arrays, particularly the string-indexed variety, under the hood of the Interactive Reports feature in APEX 3.1.

For random-access to table values, caching in PL/SQL collections can give you huge speed improvements, and reducing loops in your code by using associative arrays makes code much easier to read (and my code-legibility can always use some help).</description>
		<content:encoded><![CDATA[<p>Great topic, Tyler.  We&#8217;re using associative arrays, particularly the string-indexed variety, under the hood of the Interactive Reports feature in APEX 3.1.</p>
<p>For random-access to table values, caching in PL/SQL collections can give you huge speed improvements, and reducing loops in your code by using associative arrays makes code much easier to read (and my code-legibility can always use some help).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stew</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1253</link>
		<dc:creator>Stew</dc:creator>
		<pubDate>Mon, 25 Feb 2008 21:28:27 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1253</guid>
		<description>Tyler,

Steven also included some good examples in his seminal work (and my Bible) &quot;Oracle PL/SQL Programming&quot;.  In the fourth edition, you&#039;ll find a nice intro similar to what you started with on page 322.</description>
		<content:encoded><![CDATA[<p>Tyler,</p>
<p>Steven also included some good examples in his seminal work (and my Bible) &#8220;Oracle PL/SQL Programming&#8221;.  In the fourth edition, you&#8217;ll find a nice intro similar to what you started with on page 322.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven Feuerstein</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1242</link>
		<dc:creator>Steven Feuerstein</dc:creator>
		<pubDate>Sat, 23 Feb 2008 14:09:47 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1242</guid>
		<description>Tyler, 

I am very glad to see you spreading the word on collections (associative arrays being just one of three types of collections in PL/SQL). I strongly believe that every PL/SQL developer should be very familiar and comfortable with these structures. They have so many applications!

I encourage visitors to this blog to check out my PL/SQL Obsession page, www.ToadWorld.com/SF, and in particular the &quot;Trainings, Seminars, Presentations&quot; page. You will find several presentations and many files (in the demo.zip) to help you come up to speed quickly on collections.

Most helpful presentations:

* Hands on Collections
* 21st Century PL/SQL
* Best of PL/SQL

Warm regards,
Steven Feuerstein</description>
		<content:encoded><![CDATA[<p>Tyler, </p>
<p>I am very glad to see you spreading the word on collections (associative arrays being just one of three types of collections in PL/SQL). I strongly believe that every PL/SQL developer should be very familiar and comfortable with these structures. They have so many applications!</p>
<p>I encourage visitors to this blog to check out my PL/SQL Obsession page, <a href="http://www.ToadWorld.com/SF" rel="nofollow">http://www.ToadWorld.com/SF</a>, and in particular the &#8220;Trainings, Seminars, Presentations&#8221; page. You will find several presentations and many files (in the demo.zip) to help you come up to speed quickly on collections.</p>
<p>Most helpful presentations:</p>
<p>* Hands on Collections<br />
* 21st Century PL/SQL<br />
* Best of PL/SQL</p>
<p>Warm regards,<br />
Steven Feuerstein</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tyler Muth</title>
		<link>http://tylermuth.wordpress.com/2008/02/21/plsql-associative-arrays/#comment-1240</link>
		<dc:creator>Tyler Muth</dc:creator>
		<pubDate>Fri, 22 Feb 2008 21:06:11 +0000</pubDate>
		<guid isPermaLink="false">http://tylermuth.wordpress.com/?p=51#comment-1240</guid>
		<description>Arie Geller made an excellent point in &lt;a href=&quot;http://forums.oracle.com/forums/message.jspa?messageID=2363060&quot; rel=&quot;nofollow&quot;&gt;this forum post&lt;/a&gt; that I should include the orginal code when I make corrections so others can learn from these corrections.  Below is the original code from the 2nd example in this post:
[sourcecode language=&quot;sql&quot;]declare
    type assoc_arr is table of varchar2(255) index by varchar2(255);
    apollo_commanders assoc_arr;
    l_current_mission   varchar2(255);
begin
    apollo_commanders(&#039;Apollo 11&#039;) := &#039;Neil Armstrong&#039;;
    apollo_commanders(&#039;Apollo 12&#039;) := &#039;Pete Conrad&#039;;
    apollo_commanders(&#039;Apollo 13&#039;) := &#039;James Lovell&#039;;
    apollo_commanders(&#039;Apollo 14&#039;) := &#039;Alan Shepard&#039;;
    apollo_commanders(&#039;Apollo 15&#039;) := &#039;David Scott&#039;;
    apollo_commanders(&#039;Apollo 16&#039;) := &#039;John W. Young&#039;;
    apollo_commanders(&#039;Apollo 17&#039;) := &#039;Eugene A. Cernan&#039;;
    
    l_current_mission := apollo_commanders.first;
    loop
        exit when l_current_mission is null;
        dbms_output.put_line(&#039;Mission: &#039;&#124;&#124;l_current_mission&#124;&#124;&#039;, Commander: &#039;&#124;&#124;apollo_commanders(l_current_mission));
        if apollo_commanders.exists(apollo_commanders.next(l_current_mission)) then
            l_current_mission := apollo_commanders.next(l_current_mission);
        else
            l_current_mission := null;
        end if;
    end loop;
end;
/[/sourcecode]</description>
		<content:encoded><![CDATA[<p>Arie Geller made an excellent point in <a href="http://forums.oracle.com/forums/message.jspa?messageID=2363060" rel="nofollow">this forum post</a> that I should include the orginal code when I make corrections so others can learn from these corrections.  Below is the original code from the 2nd example in this post:</p>
<pre class="brush: sql;">declare
    type assoc_arr is table of varchar2(255) index by varchar2(255);
    apollo_commanders assoc_arr;
    l_current_mission   varchar2(255);
begin
    apollo_commanders('Apollo 11') := 'Neil Armstrong';
    apollo_commanders('Apollo 12') := 'Pete Conrad';
    apollo_commanders('Apollo 13') := 'James Lovell';
    apollo_commanders('Apollo 14') := 'Alan Shepard';
    apollo_commanders('Apollo 15') := 'David Scott';
    apollo_commanders('Apollo 16') := 'John W. Young';
    apollo_commanders('Apollo 17') := 'Eugene A. Cernan';

    l_current_mission := apollo_commanders.first;
    loop
        exit when l_current_mission is null;
        dbms_output.put_line('Mission: '||l_current_mission||', Commander: '||apollo_commanders(l_current_mission));
        if apollo_commanders.exists(apollo_commanders.next(l_current_mission)) then
            l_current_mission := apollo_commanders.next(l_current_mission);
        else
            l_current_mission := null;
        end if;
    end loop;
end;
/</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
