Edit D:\app\Administrator\product\11.2.0\dbhome_1\oc4j\j2ee\oc4j_applications\applications\em\em\online_help\tdddg\tdddg_subprograms045.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:24Z" /> <meta name="robots" content="noarchive" /> <meta name="doctitle" content="Declaring 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_subprograms044.htm" title="Previous" type="text/html" /> <link rel="next" href="tdddg_subprograms046.htm" title="Next" type="text/html" /> <title>Declaring 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_subprograms044.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_subprograms046.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="BABBIBHD" name="BABBIBHD"></a><a id="TDDDG99950" name="TDDDG99950"></a></p> <div class="sect2"><!-- infolevel="all" infotype="General" --> <h1>Declaring Associative Arrays</h1> <a name="BEGIN" id="BEGIN"></a> <p>To declare an <a id="sthref513" name="sthref513"></a>associative array, you declare an associative array type, and then declare a variable of that type. The simplest syntax is:</p> <pre xml:space="preserve" class="oac_no_warn"> TYPE <span class="italic">array_type</span> IS TABLE OF <span class="italic">element_type</span> INDEX BY <span class="italic">key_type</span>; <span class="italic">array_name array_type</span>; </pre> <p>An efficient way to declare an associative array is with a <a id="sthref514" name="sthref514"></a>cursor, using the following procedure. The procedure uses each necessary statement in its simplest form, but provides references to its complete syntax.</p> <a id="TDDDG241" name="TDDDG241"></a> <p class="subhead2">To use a cursor to declare an associative array:</p> <ol> <li> <p>In the declarative part:</p> <ol> <li> <p>Declare the cursor:</p> <pre xml:space="preserve" class="oac_no_warn"> CURSOR <span class="italic">cursor_name</span> IS <span class="italic">query</span>; </pre> <p>For complete explicit cursor declaration syntax, see <a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS01307','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></a>.</p> </li> <li> <p>Declare the associative array type:</p> <pre xml:space="preserve" class="oac_no_warn"> TYPE <span class="italic">array_type</span> IS TABLE OF <span class="italic">cursor_name</span>%ROWTYPE INDEX BY { PLS_INTEGER | VARCHAR2 <code><span class="codeinlineitalic">length</span></code> } </pre> <p>For complete associative array type declaration syntax, see <a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS01313','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></a>.</p> </li> <li> <p>Declare an associative array variable of that type:</p> <pre xml:space="preserve" class="oac_no_warn"> <span class="italic">array_name array_type</span>; </pre> <p>For complete variable declaration syntax, see <a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS01388','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 create two associative arrays, <code>employees_jobs</code> and <code>jobs_</code>, and then declares a third associative array, <code>job_titles_type</code>, without using a cursor. The first two arrays are indexed by integer; the third is indexed by string.</p> <div class="helpinfonote"> <p><span class="bold">Note: </span>The <code>ORDER</code> <code>BY</code> clause in the declaration of <code>employees_jobs_cursor</code> determines the storage order of the elements of the associative array <code>employee_jobs</code>.</p> </div> <div class="example"><a id="BABCJGAD" name="BABCJGAD"></a><a id="TDDDG242" name="TDDDG242"></a> <p class="titleinexample">Declaring Associative Arrays</p> <pre xml:space="preserve" class="oac_no_warn"> DECLARE -- Declare cursor: CURSOR employees_jobs_cursor IS SELECT FIRST_NAME, LAST_NAME, JOB_ID FROM EMPLOYEES ORDER BY JOB_ID, LAST_NAME, FIRST_NAME; -- Declare associative array type: TYPE employees_jobs_type IS TABLE OF employees_jobs_cursor%ROWTYPE INDEX BY PLS_INTEGER; -- Declare associative array: employees_jobs employees_jobs_type; -- Use same procedure to declare another associative array: CURSOR jobs_cursor IS SELECT JOB_ID, JOB_TITLE FROM JOBS; TYPE jobs_type IS TABLE OF jobs_cursor%ROWTYPE INDEX BY PLS_INTEGER; jobs_ jobs_type; -- Declare associative array without using cursor: TYPE job_titles_type IS TABLE OF JOBS.JOB_TITLE%TYPE INDEX BY JOBS.JOB_ID%TYPE; -- jobs.job_id%type is varchar2(10) job_titles job_titles_type; BEGIN NULL; 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="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS01307','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></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_subprograms044.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_subprograms046.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