Edit D:\app\Administrator\product\11.2.0\dbhome_1\oc4j\j2ee\oc4j_applications\applications\em\em\online_help\tdddg\tdddg_subprograms035.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="Tutorial: Creating and Invoking a Subprogram with a Record Parameter" /> <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_subprograms034.htm" title="Previous" type="text/html" /> <link rel="next" href="tdddg_subprograms036.htm" title="Next" type="text/html" /> <title>Tutorial: Creating and Invoking a Subprogram with a Record Parameter</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_subprograms034.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_subprograms036.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="BABCDCJA" name="BABCDCJA"></a><a id="TDDDG99956" name="TDDDG99956"></a></p> <div class="sect2"> <h1>Tutorial: Creating and Invoking a Subprogram with a Record Parameter</h1> <a name="BEGIN" id="BEGIN"></a> <p>If you declared the <code>RECORD</code> type <code>sal_info</code> in <a href="tdddg_subprograms034.htm#BABGIEHF">"Tutorial: Declaring a RECORD Type"</a>, this tutorial shows how to use the SQL Developer tool Edit to do the following:</p> <ul> <li> <p>Create a procedure, <a id="sthref450" name="sthref450"></a><code>salary_schedule</code>, which has a parameter of type <a id="sthref451" name="sthref451"></a><code>sal_info</code>.</p> </li> <li> <p>Change the <code>eval_frequency</code> function so that it declares a record, <code>emp_sal</code>, of the type <code>sal_info</code>, populates its fields, and passes it to the <a id="sthref452" name="sthref452"></a><code>salary_schedule</code> procedure.</p> </li> </ul> <p>Because <code>eval_frequency</code> will invoke <code>salary_schedule</code>, the declaration of <code>salary_schedule</code> must precede the declaration of <code>eval_frequency</code> (otherwise, the package will not compile). However, the definition of <code>salary_schedule</code> can be anywhere in the package body.</p> <a id="TDDDG235" name="TDDDG235"></a> <p class="subhead2">To create salary_schedule and change eval_frequency:</p> <ol> <li> <p>On the Connections tab, expand the <code>hr_conn</code> information by clicking the plus sign (<span class="bold">+</span>) to the left of the <code>hr_conn</code> icon.</p> <p>Under the <code>hr_conn</code> icon, a list of schema object types appears.</p> </li> <li> <p>Expand <span class="bold">Packages</span>.</p> <p>A list of packages appears.</p> </li> <li> <p>Expand <span class="bold">EMP_EVAL</span>.</p> <p>A list appears.</p> </li> <li> <p>Right-click <span class="bold">EMP_EVAL Body</span>.</p> <p>A list of choices appears.</p> </li> <li> <p>Click <span class="bold">Edit</span>.</p> <p>The <code>EMP_EVAL</code> Body pane appears, showing the code for the package body.</p> </li> <li> <p>In the <code>EMP_EVAL</code> Body pane, immediately before <code>END emp_eval</code>, add this definition of the <code>salary_schedule</code> procedure:</p> <pre xml:space="preserve" class="oac_no_warn"> PROCEDURE salary_schedule (emp IN sal_info) AS accumulating_sal NUMBER; BEGIN DBMS_OUTPUT.PUT_LINE('If salary ' || emp.sal || ' increases by ' || ROUND((emp.sal_raise * 100),0) || '% each year, it will be:'); accumulating_sal := emp.sal; WHILE accumulating_sal <= emp.sal_max LOOP accumulating_sal := accumulating_sal * (1 + emp.sal_raise); DBMS_OUTPUT.PUT_LINE(ROUND(accumulating_sal,2) ||', '); END LOOP; END salary_schedule; </pre> <p>A new <code>EMP_EVAL</code> Body pane opens, showing the changed <code>CREATE</code> <code>PACKAGE</code> <code>BODY</code> statement. The title of the pane is in italic font, which indicates that the changes have not been saved to the database.</p> </li> <li> <p>In the <code>EMP_EVAL</code> Body pane, enter the code shown in bold font, in this position:</p> <pre xml:space="preserve" class="oac_no_warn"> create or replace PACKAGE BODY EMP_EVAL AS <span class="bold">FUNCTION eval_frequency (emp_id EMPLOYEES.EMPLOYEE_ID%TYPE)</span> <span class="bold">RETURN PLS_INTEGER;</span> <span class="bold">PROCEDURE salary_schedule(emp IN sal_info);</span> <span class="bold">PROCEDURE add_eval(employee_id IN NUMBER, today IN DATE);</span> PROCEDURE eval_department (dept_id IN NUMBER) AS </pre></li> <li> <p>Edit the <code>eval_frequency</code> function, making the changes shown in bold font:</p> <pre xml:space="preserve" class="oac_no_warn"> FUNCTION eval_frequency (emp_id EMPLOYEES.EMPLOYEE_ID%TYPE) RETURN PLS_INTEGER AS h_date EMPLOYEES.HIRE_DATE%TYPE; today EMPLOYEES.HIRE_DATE%TYPE; eval_freq PLS_INTEGER; <span class="bold">emp_sal SAL_INFO; -- replaces sal, sal_raise, and sal_max</span> BEGIN SELECT SYSDATE INTO today FROM DUAL; SELECT HIRE_DATE INTO h_date FROM EMPLOYEES WHERE EMPLOYEE_ID = emp_id; IF ((h_date + (INTERVAL '120' MONTH)) < today) THEN eval_freq := 1; <span class="bold">/* populate emp_sal */</span> <span class="bold">SELECT JOB_ID INTO emp_sal.j_id FROM EMPLOYEES</span> <span class="bold">WHERE EMPLOYEE_ID = emp_id;</span> <span class="bold">SELECT MIN_SALARY INTO emp_sal.sal_min FROM JOBS</span> <span class="bold">WHERE JOB_ID = emp_sal.j_id;</span> <span class="bold">SELECT MAX_SALARY INTO emp_sal.sal_max FROM JOBS</span> <span class="bold">WHERE JOB_ID = emp_sal.j_id;</span> <span class="bold">SELECT SALARY INTO emp_sal.sal FROM EMPLOYEES</span> <span class="bold">WHERE EMPLOYEE_ID = emp_id;</span> <span class="bold">emp_sal.sal_raise := 0; -- default</span> CASE <span class="bold">emp_sal.</span>j_id WHEN 'PU_CLERK' THEN <span class="bold">emp_sal.</span>sal_raise := 0.08; WHEN 'SH_CLERK' THEN <span class="bold">emp_sal.</span>sal_raise := 0.07; WHEN 'ST_CLERK' THEN <span class="bold">emp_sal.</span>sal_raise := 0.06; WHEN 'HR_REP' THEN <span class="bold">emp_sal.</span>sal_raise := 0.05; WHEN 'PR_REP' THEN <span class="bold">emp_sal.</span>sal_raise := 0.05; WHEN 'MK_REP' THEN <span class="bold">emp_sal.</span>sal_raise := 0.04; ELSE NULL; END CASE; IF (<span class="bold">emp_sal.</span>sal_raise != 0) THEN <span class="bold">salary_schedule(emp_sal);</span> END IF; ELSE eval_freq := 2; END IF; RETURN eval_freq; END eval_frequency; </pre></li> <li> <p>Click <span class="bold">Compile</span>.</p> </li> </ol> <div class="helpinfonotealso"> <h2>Related Topics</h2> <p><a href="tdddg_subprograms032.htm#CIHHCJDI">Using Records and Cursors</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_subprograms034.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_subprograms036.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