Edit D:\app\Administrator\product\11.2.0\dbhome_1\oc4j\j2ee\oc4j_applications\applications\em\em\online_help\tdddg\tdddg_subprograms046.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <script src="./callback.js" type="text/javascript"></script> <noscript>Your browser does not support JavaScript. This help page requires JavaScript to render correctly.</noscript> </head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta name="generator" content="Oracle DARB XHTML Converter (Mode = ohj/ohw) - Version 5.1.1 Build 005" /> <meta name="date" content="2009-04-21T9:46:25Z" /> <meta name="robots" content="noarchive" /> <meta name="doctitle" content="Populating Associative Arrays" /> <meta name="relnum" content="11g Release 2 (11.2)" /> <meta name="partnum" content="E10766-01" /> <link rel="copyright" href="./dcommon/html/cpyr.htm" title="Copyright" type="text/html" /> <link rel="stylesheet" href="./dcommon/css/blafdoc.css" title="Oracle BLAFDoc" type="text/css" /> <link rel="contents" href="toc.htm" title="Contents" type="text/html" /> <link rel="prev" href="tdddg_subprograms045.htm" title="Previous" type="text/html" /> <link rel="next" href="tdddg_subprograms047.htm" title="Next" type="text/html" /> <title>Populating Associative Arrays</title> </head> <body> <div class="zz-skip-header"><a href="#BEGIN">Skip Headers</a></div> <table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%"> <col width="86%" /> <col width="*" /> <tr valign="bottom"> <td align="left"></td> <td align="center"><a href="tdddg_subprograms045.htm"><img width="24" height="24" src="./dcommon/gifs/leftnav.gif" alt="Previous" /><br /> <span class="icon">Previous</span></a> </td> <td align="center"><a href="tdddg_subprograms047.htm"><img width="24" height="24" src="./dcommon/gifs/rightnav.gif" alt="Next" /><br /> <span class="icon">Next</span></a></td> </tr> </table> <p><a id="BABJHJBJ" name="BABJHJBJ"></a><a id="TDDDG99949" name="TDDDG99949"></a></p> <div class="sect2"><!-- infolevel="all" infotype="General" --> <h1>Populating Associative Arrays</h1> <a name="BEGIN" id="BEGIN"></a> <p>The most efficient way to <a id="sthref515" name="sthref515"></a>populate a dense associative array is with a <a id="sthref516" name="sthref516"></a><a id="sthref517" name="sthref517"></a>cursor and the <a id="sthref518" name="sthref518"></a><code>FETCH</code> statement with the <a id="sthref519" name="sthref519"></a><code>BULK</code> <code>COLLECT</code> <code>INTO</code> clause, using the following procedure. The procedure uses each necessary statement in its simplest form, but provides references to its complete syntax.</p> <p>You cannot use the following procedure to populate a sparse associative array. Instead, you must use an assignment statement inside a loop statement. For information about <a id="sthref520" name="sthref520"></a><a id="sthref521" name="sthref521"></a>loop statements, see <a href="tdddg_subprograms025.htm#CIHHFJFJ">"Controlling Program Flow"</a>.</p> <a id="TDDDG243" name="TDDDG243"></a> <p class="subhead2">To use a cursor to populate an associative array indexed by integer:</p> <ol> <li> <p>If you have not done so, declare an associative array with a cursor, using the procedure in <a href="tdddg_subprograms045.htm#BABBIBHD">"Declaring Associative Arrays"</a>.</p> </li> <li> <p>In the executable part of the PL/SQL unit in which you declared the associative array:</p> <ol> <li> <p>Open the cursor:</p> <pre xml:space="preserve" class="oac_no_warn"> OPEN <span class="italic">cursor_name</span>; </pre> <p>For complete <code>OPEN</code> statement syntax, see <a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS01332','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></a>.</p> </li> <li> <p>Fetch all rows from the cursor into the associative array variable at once, using a <code>FETCH</code> statement with the <code>BULK</code> <code>COLLECT</code> <code>INTO</code> clause:</p> <pre xml:space="preserve" class="oac_no_warn"> FETCH <span class="italic">cursor_name</span> BULK COLLECT INTO <span class="italic">aa_variable</span>; </pre> <p>For complete <code>FETCH</code> statement syntax, see <a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS01320','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></a>.</p> </li> <li> <p>Close the cursor:</p> <pre xml:space="preserve" class="oac_no_warn"> CLOSE <span class="italic">cursor_name</span>; </pre> <p>For complete <code>CLOSE</code> statement syntax, see <a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS01305','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></a>.</p> </li> </ol> </li> </ol> <p>The following example uses the preceding procedure to populate the associative arrays <code>employees_jobs</code> and <code>jobs_</code>, which are indexed by integer. Then it uses an assignment statement inside a statement to populate the associative array <code>job_titles_type</code>, which is indexed by string.</p> <div class="example"><a id="CIHJHGAI" name="CIHJHGAI"></a><a id="TDDDG244" name="TDDDG244"></a> <p class="titleinexample">Populating Associative Arrays</p> <pre xml:space="preserve" class="oac_no_warn"> -- Declarative part from <a href="tdddg_subprograms045.htm#BABBIBHD">Declaring Associative Arrays</a> goes here. BEGIN -- Populate associative arrays indexed by integer: OPEN employees_jobs_cursor; FETCH employees_jobs_cursor BULK COLLECT INTO employees_jobs; CLOSE employees_jobs_cursor; OPEN jobs_cursor; FETCH jobs_cursor BULK COLLECT INTO jobs_; CLOSE jobs_cursor; -- Populate associative array indexed by string: FOR i IN 1..jobs_.COUNT() LOOP job_titles(jobs_(i).job_id) := jobs_(i).job_title; END LOOP; END; / </pre></div> <!-- class="example" --> <div class="helpinfonotealso"> <h2>Related Topics</h2> <p><a href="tdddg_subprograms036.htm#BABJBEGE">About Cursors</a></p> <p><a href="tdddg_subprograms042.htm#BABDFGAA">Using Associative Arrays</a></p> </div> </div> <!-- class="sect2" --> <!-- Start Footer --> <div class="footer"> <table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%"> <col width="86%" /> <col width="*" /> <tr> <td align="left"><span class="copyrightlogo">Copyright © 1996, 2009, Oracle and/or its affiliates. All rights reserved.</span><br /> <a href="./dcommon/html/cpyr.htm"><span class="copyrightlogo">Legal Notices</span></a></td> <td align="center"><a href="tdddg_subprograms045.htm"><img width="24" height="24" src="./dcommon/gifs/leftnav.gif" alt="Previous" /><br /> <span class="icon">Previous</span></a> </td> <td align="center"><a href="tdddg_subprograms047.htm"><img width="24" height="24" src="./dcommon/gifs/rightnav.gif" alt="Next" /><br /> <span class="icon">Next</span></a></td> </tr> </table> </div> <!-- class="footer" --> </body> </html>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de