<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Oracle Illustrated</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/oracle</link>
	<description>Oracle for Developers - SQL / PL/SQL / Basic DBA / Performance Tuning and the others.</description>
	<lastBuildDate>Thu, 16 Sep 2010 08:56:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Generic DML Error logging</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/generic-dml-error-logging/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/generic-dml-error-logging/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 08:56:33 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/generic-dml-error-logging/</guid>
		<description><![CDATA[Create couple of transaction tables and one error log table. Create table emp1 (id number, dept_no number, salary number) create table dept1 (id number, name varchar2(10)) Create a generic error logging table - create table error_log     (ora_err_number$ number,      ora_err_mesg$ varchar2(2000),      ora_err_rowid$ rowid,      ora_err_optyp$ varchar2(2),      ora_err_tag$ varchar2(2000),      ID    NUMBER     ) [...]]]></description>
				<content:encoded><![CDATA[
<p>Create couple of transaction tables and one error log table.</p>
<p>Create table emp1 (id number, dept_no number, salary number)</p>
<p>create table dept1 (id number, name varchar2(10))</p>
<p><strong><em>Create a generic error logging table -</em></strong></p>
<p>create table error_log<br />
    (ora_err_number$ number,<br />
     ora_err_mesg$ varchar2(2000),<br />
     ora_err_rowid$ rowid,<br />
     ora_err_optyp$ varchar2(2),<br />
     ora_err_tag$ varchar2(2000),<br />
     ID    NUMBER<br />
    )<br />
/</p>
<p>We know about ORA_ERR_NUMBER$, ORA_ERR_MESG$, ORA_ERR_ROWID$ (will be populated only for update / delete), ORA_ERR_OPTYP$, ORA_ERR_TAG$ &#8211; These are mandatory columns for any DML error logging table. Note, I have created a column called <strong><span style="text-decoration: underline">ID</span></strong> which is common to EMP1 and DEPT1 table.</p>
<p>Now, lets try to perform INSERT into EMP1 and DEPT1 tables. Here I am using multi table inserts just for the sake of it.</p>
<p>INSERT ALL<br />
    WHEN (1 = 1) THEN<br />
    INTO emp1 (id, dept_no, salary)<br />
    VALUES (empid, depid, <strong>&#8216;a&#8217;</strong>)<br />
         LOG ERRORS INTO error_log (<strong>&#8216;While inserting into emp1 table&#8217;</strong>) REJECT LIMIT UNLIMITED<br />
    WHEN (1 = 1) THEN<br />
    INTO dept1 (id, name)<br />
    VALUES (depid, name)<br />
         LOG ERRORS INTO error_log (<strong>&#8216;While inserting into dept1 table&#8217;</strong>) REJECT LIMIT UNLIMITED    SELECT object_id empid,<br />
           rownum depid,<br />
           object_name name,<br />
    object_id salary FROM all_objects where rownum &lt; 50   <br />
/</p>
<p><strong>Query ERROR_LOG table -</strong></p>
<p> </p>
<table style="width: 828pt" border="0" cellspacing="0" cellpadding="0" width="1103">
<col style="width: 104pt" span="1" width="139"></col>
<col style="width: 453pt" span="1" width="604"></col>
<col style="width: 48pt" span="1" width="64"></col>
<col style="width: 32pt" span="1" width="42"></col>
<col style="width: 143pt" span="1" width="190"></col>
<col style="width: 48pt" span="1" width="64"></col>
<tbody>
<tr style="height: 12.75pt">
<td class="xl24" style="width: 104pt;height: 12.75pt;border: windowtext 0.5pt solid" width="139" height="17"><strong><span style="font-family: Arial;font-size: x-small">ORA_ERR_NUMBER$</span></strong></td>
<td class="xl24" style="width: 453pt" width="604"><strong><span style="font-family: Arial;font-size: x-small">ORA_ERR_MESG$</span></strong></td>
<td class="xl24" style="width: 48pt" width="64"><strong><span style="font-family: Arial;font-size: x-small">ORA_ERR_ROWID$</span></strong></td>
<td class="xl24" style="width: 32pt" width="42"><strong><span style="font-family: Arial;font-size: x-small">ORA_ERR_OPTYP$</span></strong></td>
<td class="xl24" style="width: 143pt" width="190"><strong><span style="font-family: Arial;font-size: x-small">ORA_ERR_TAG$</span></strong></td>
<td class="xl24" style="width: 48pt" width="64"><strong><span style="font-family: Arial;font-size: x-small">ID</span></strong></td>
</tr>
<tr style="height: 12.75pt">
<td class="xl25" style="height: 12.75pt" height="17" align="right"><span style="font-family: Arial;font-size: x-small">1722</span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small">ORA-01722: invalid number</span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small"> </span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small">I</span></td>
<td class="xl27"><span style="font-family: Arial;color: #ff0000;font-size: x-small">While inserting into emp1 table</span></td>
<td class="xl29" align="right"><strong><span style="font-family: Arial;color: #ff0000;font-size: x-small">367</span></strong></td>
</tr>
<tr style="height: 12.75pt">
<td class="xl25" style="height: 12.75pt" height="17" align="right"><span style="font-family: Arial;font-size: x-small">1722</span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small">ORA-01722: invalid number</span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small"> </span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small">I</span></td>
<td class="xl27"><span style="font-family: Arial;color: #ff0000;font-size: x-small">While inserting into emp1 table</span></td>
<td class="xl29" align="right"><strong><span style="font-family: Arial;color: #ff0000;font-size: x-small">369</span></strong></td>
</tr>
<tr style="height: 12.75pt">
<td class="xl25" style="height: 12.75pt" height="17" align="right"><span style="font-family: Arial;font-size: x-small">1722</span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small">ORA-01722: invalid number</span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small"> </span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small">I</span></td>
<td class="xl27"><span style="font-family: Arial;color: #ff0000;font-size: x-small">While inserting into emp1 table</span></td>
<td class="xl29" align="right"><strong><span style="font-family: Arial;color: #ff0000;font-size: x-small">370</span></strong></td>
</tr>
<tr style="height: 12.75pt">
<td class="xl25" style="height: 12.75pt" height="17" align="right"><span style="font-family: Arial;font-size: x-small">1722</span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small">ORA-01722: invalid number</span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small"> </span></td>
<td class="xl25"><span style="font-family: Arial;font-size: x-small">I</span></td>
<td class="xl27"><span style="font-family: Arial;color: #ff0000;font-size: x-small">While inserting into emp1 table</span></td>
<td class="xl29" align="right"><strong><span style="font-family: Arial;color: #ff0000;font-size: x-small">372</span></strong></td>
</tr>
<tr style="height: 12.75pt">
<td class="xl26" style="height: 12.75pt" height="17" align="right"><span style="font-family: Arial;font-size: x-small">12899</span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small">ORA-12899: value too large for column &#8220;RFD_1FTEST&#8221;.&#8221;DEPT1&#8243;.&#8221;NAME&#8221; (actual: 20, maximum: 10)</span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small"> </span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small">I</span></td>
<td class="xl28"><span style="font-family: Arial;color: #ff0000;font-size: x-small">While inserting into dept1 table</span></td>
<td class="xl30" align="right"><strong><span style="font-family: Arial;color: #ff0000;font-size: x-small">7</span></strong></td>
</tr>
<tr style="height: 12.75pt">
<td class="xl26" style="height: 12.75pt" height="17" align="right"><span style="font-family: Arial;font-size: x-small">12899</span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small">ORA-12899: value too large for column &#8220;RFD_1FTEST&#8221;.&#8221;DEPT1&#8243;.&#8221;NAME&#8221; (actual: 19, maximum: 10)</span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small"> </span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small">I</span></td>
<td class="xl28"><span style="font-family: Arial;color: #ff0000;font-size: x-small">While inserting into dept1 table</span></td>
<td class="xl30" align="right"><strong><span style="font-family: Arial;color: #ff0000;font-size: x-small">8</span></strong></td>
</tr>
<tr style="height: 12.75pt">
<td class="xl26" style="height: 12.75pt" height="17" align="right"><span style="font-family: Arial;font-size: x-small">12899</span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small">ORA-12899: value too large for column &#8220;RFD_1FTEST&#8221;.&#8221;DEPT1&#8243;.&#8221;NAME&#8221; (actual: 19, maximum: 10)</span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small"> </span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small">I</span></td>
<td class="xl28"><span style="font-family: Arial;color: #ff0000;font-size: x-small">While inserting into dept1 table</span></td>
<td class="xl30" align="right"><strong><span style="font-family: Arial;color: #ff0000;font-size: x-small">9</span></strong></td>
</tr>
<tr style="height: 12.75pt">
<td class="xl26" style="height: 12.75pt" height="17" align="right"><span style="font-family: Arial;font-size: x-small">12899</span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small">ORA-12899: value too large for column &#8220;RFD_1FTEST&#8221;.&#8221;DEPT1&#8243;.&#8221;NAME&#8221; (actual: 21, maximum: 10)</span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small"> </span></td>
<td class="xl26"><span style="font-family: Arial;font-size: x-small">I</span></td>
<td class="xl28"><span style="font-family: Arial;color: #ff0000;font-size: x-small">While inserting into dept1 table</span></td>
<td class="xl30" align="right"><strong><span style="font-family: Arial;color: #ff0000;font-size: x-small">10</span></strong></td>
</tr>
</tbody>
</table>
<p> </p>
<p>Explanation for above result set &#8211; The first 4 records Oracle error number 1722 &#8211; is due to insertion of character value in number field in EMP1 table.</p>
<p>The next 4 records Oracle error number 12899 is due to insertion of value larger than expected into DEPT1 table name field.</p>
<p>Note the ID column &#8211; that has the value of respective ID&#8217;s for the table concerned. Now, we can easily identify which table it belongs to from ORA_ERR_TAG$ table &#8211; which contains the description. In this way we can make DML error loging process generic and efficient. DML error logging is quite good when we try to perform INSERT based on SELECT from global temporary table / normal table. As there is no direct error logging feature for bulk inserts using SELECT as we have it for BULK DML operations using COLLECTIONS.</p>
<p>Having said all this - its quite important to know why it had caused the error in first place.</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/generic-dml-error-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Import Stats from one DB to another &#8211; Quick way</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/import-stats-from-one-db-to-another-quick-way/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/import-stats-from-one-db-to-another-quick-way/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 08:04:02 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/import-stats-from-one-db-to-another-quick-way/</guid>
		<description><![CDATA[      Database 1-  exec                dbms_stats.create_stat_table(ownname =&#62; &#8216;&#60;DBNMAME&#62;&#8216;, stattab =&#62; &#8216;STATS&#8217;); exec dbms_stats.export_table_stats(&#8216;&#60;DBNAME&#62;&#8216;,&#8216;&#60;table name&#62;&#8217;,null,&#8217;STATS&#8217;,null,true,null); Database 2- CREATE TABLE STATS AS SELECT * FROM STATS@&#60;DBNAME&#62;;    exec               dbms_stats.import_table_stats &#8216;&#60;DBAME2&#62;&#8216;,&#8216;&#60;table name&#62;&#8217;,null,&#8216;STATS&#8217;,null,true,&#8216;&#60;DBNAME2&#62;&#8216;);]]></description>
				<content:encoded><![CDATA[
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size: x-small">Database 1-<span style="font-size: x-small"> </p>
<p></span></span></p>
<p><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">exec</span></span></span></p>
<p></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"> </span></span></p>
<p><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><font face="Courier" size="2" color="#0000ff"><font face="Courier" size="2" color="#0000ff"> </p>
<p></font></font></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><font face="Courier" size="2" color="#0000ff"> </p>
<p></font></span></span> </p>
<p></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"> </span></p>
<p><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><font face="Courier" size="2" color="#0000ff"> </p>
<p></font></span></span> </p>
<p></span></span></p>
<p><span style="font-family: Courier;font-size: x-small"><span style="font-family: Courier;font-size: x-small"> <strong><em>dbms_stats.create_stat_table</em></strong></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">(</span></span></span><span style="font-family: Courier;font-size: x-small"><span style="font-family: Courier;font-size: x-small">ownname </span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">=&gt;</span></span></span><span style="font-family: Courier;font-size: x-small"><span style="font-family: Courier;font-size: x-small"> </span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&lt;DBNMAME&gt;</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">,</span></span></span><span style="font-family: Courier;font-size: x-small"><span style="font-family: Courier;font-size: x-small"> stattab </span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">=&gt;</span></span></span><span style="font-family: Courier;font-size: x-small"><span style="font-family: Courier;font-size: x-small"> </span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;STATS&#8217;</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">);</span></span></span></p>
<p><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">exec </span></span></span><span style="font-family: Courier;font-size: x-small"><span style="font-family: Courier;font-size: x-small"><strong><em>dbms_stats.export_table_stats</em></strong></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">(</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&lt;DBNAME&gt;</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">,</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;&lt;table name&gt;&#8217;</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">,null,&#8217;</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">STATS&#8217;</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">,null,true,null);</span></span></span></p>
<p><span style="font-size: x-small">Database 2-</span></p>
<p><span style="font-family: Courier;font-size: x-small"><span style="font-family: Courier;font-size: x-small">CREATE TABLE STATS AS SELECT * FROM <a href="mailto:STATS@&lt;DBNAME">STATS@&lt;DBNAME</a>&gt;;<span style="font-family: Courier;font-size: x-small"><span style="font-family: Courier;font-size: x-small"> </p>
<p></span></span></span><span style="font-family: Courier;font-size: x-small"> </p>
<p></span></span></p>
<p><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">exec</span></span></span></p>
<p></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"> </span></span></p>
<p><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><font face="Courier" size="2" color="#0000ff"><font face="Courier" size="2" color="#0000ff"> </p>
<p></font></font></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><font face="Courier" size="2" color="#0000ff"> </p>
<p></font></span></span> </p>
<p></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"> </span></p>
<p><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><font face="Courier" size="2" color="#0000ff"> </p>
<p></font></span></span> </p>
<p></span></span></p>
<p><span style="font-family: Courier;font-size: x-small"><span style="font-family: Courier;font-size: x-small"><strong><em>dbms_stats.import_table_stats </em></strong></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&lt;DBAME2&gt;</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">,</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;&lt;table name&gt;&#8217;</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">,null,</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;STATS&#8217;</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">,null,true,</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&lt;DBNAME2&gt;</span></span></span><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small"><span style="font-family: Courier;color: #ff0000;font-size: x-small">&#8216;</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small"><span style="font-family: Courier;color: #0000ff;font-size: x-small">);</span></span></span><span style="font-family: Courier;color: #0000ff;font-size: x-small"></span></p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/import-stats-from-one-db-to-another-quick-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analytical way &#8211; To find Nth maximum value from a table</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-nth-maximum-value-from-a-table/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-nth-maximum-value-from-a-table/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 15:13:19 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-nth-maximum-value-from-a-table/</guid>
		<description><![CDATA[To find NTH maximum value from a table, we may need to query the same table twice to get the desired output. This will lead to table scans / index scans for the same table twice. The same can be achieved via analytical functions by querying the table once. Have enclosed the execution plan and [...]]]></description>
				<content:encoded><![CDATA[
<p>To find NTH maximum value from a table, we may need to query the same table twice to get the desired output. This will lead to table scans / index scans for the same table twice. The same can be achieved via analytical functions by querying the table once. Have enclosed the execution plan and have highlighted the difference.</p>
<p><span style="font-weight:bold">Non analytical way </span></p>
<p>SQL&gt; SELECT DISTINCT SAL FROM SCOTT.EMP A WHERE &amp;N=(SELECT COUNT (DISTINCT B.SAL<br />
)<br />
2 FROM SCOTT.EMP B WHERE A.SAL&lt;=B.SAL);<br />
Enter value for n: 5<br />
old 1: SELECT DISTINCT SAL FROM SCOTT.EMP A WHERE &amp;N=(SELECT COUNT (DISTINCT B<br />
.SAL)<br />
new 1: SELECT DISTINCT SAL FROM SCOTT.EMP A WHERE 5=(SELECT COUNT (DISTINCT B.<br />
SAL)</p>
<p>SAL<br />
&#8212;&#8212;&#8212;-<br />
2450</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 3556451907</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 1 | 4 | 25 (4)| 00:00:01 |<br />
| 1 | HASH UNIQUE | | 1 | 4 | 25 (4)| 00:00:01 |<br />
|* 2 | FILTER | | | | | |<br />
<span style="font-weight:bold">| 3 | TABLE ACCESS FULL | EMP | 14 | 56 | 3 (0)| 00:00:01 |</span><br />
| 4 | SORT GROUP BY | | 1 | 4 | | |<br />
<span style="font-weight:bold">|* 5 | TABLE ACCESS FULL| EMP | 1 | 4 | 3 (0)| 00:00:01 |</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; filter( (SELECT COUNT(DISTINCT &#8220;B&#8221;.&#8221;SAL&#8221;) FROM &#8220;SCOTT&#8221;.&#8221;EMP&#8221; &#8220;B&#8221; WHERE &#8220;B&#8221;.&#8221;SAL&#8221;&gt;=:B1)=5)<br />
5 &#8211; filter(&#8220;B&#8221;.&#8221;SAL&#8221;&gt;=:B1)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
187 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">127 consistent gets</span><br />
4 physical reads<br />
0 redo size<br />
414 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
17 sorts (memory)<br />
0 sorts (disk)<br />
1 rows processed</p>
<p><span style="font-weight:bold">USING Analytical functions -<br />
</span></p>
<p>SELECT * FROM<br />
(SELECT e.*, RANK() OVER ( ORDER BY e.SAL DESC) rnk FROM scott.emp e) qry<br />
WHERE qry.rnk = 6;</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
DEPTNO RNK<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
7782 CLARK MANAGER 7839 09-JUN-81 2450<br />
10 6</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 3291446077</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 1 | VIEW | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 2 | WINDOW SORT PUSHED RANK| | 14 | 518 | 4 (25)| 00:00:01|<br />
<span style="font-weight:bold">| 3 | TABLE ACCESS FULL | EMP | 14 | 518 | 3 (0)| 00:00:01</span>|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;QRY&#8221;.&#8221;RNK&#8221;=6)<br />
2 &#8211; filter(RANK() OVER ( ORDER BY INTERNAL_FUNCTION(&#8220;E&#8221;.&#8221;SAL&#8221;) DESC)<br />
SQL&gt; SELECT * FROM<br />
2 (SELECT e.*, RANK() OVER ( ORDER BY e.SAL DESC) rnk FROM scott.emp e) qry<br />
3 WHERE qry.rnk = 6;</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
DEPTNO RNK<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
7782 CLARK MANAGER 7839 09-JUN-81 2450<br />
10 6</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 3291446077</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>-</p>
<p>| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time<br />
|</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 1 | VIEW | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 2 | WINDOW SORT PUSHED RANK| | 14 | 518 | 4 (25)| 00:00:01|<br />
<span style="font-weight:bold">| 3 | TABLE ACCESS FULL | EMP | 14 | 518 | 3 (0)| 00:00:01|</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;QRY&#8221;.&#8221;RNK&#8221;=6)<br />
2 &#8211; filter(RANK() OVER ( ORDER BY INTERNAL_FUNCTION(&#8220;E&#8221;.&#8221;SAL&#8221;) DESC<br />
)&lt;=6)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
144 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">28 consistent gets</span><br />
0 physical reads<br />
0 redo size<br />
888 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
1 sorts (memory)<br />
0 sorts (disk)<br />
1 rows processed</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-nth-maximum-value-from-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analytical way &#8211; Retrieve the Nth row from a table</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-retrieve-the-nth-row-from-a-table/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-retrieve-the-nth-row-from-a-table/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 15:12:56 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-retrieve-the-nth-row-from-a-table/</guid>
		<description><![CDATA[To retrieve Nth row from a table using the usual way it might require to query the same table thrice (can write it in different way also). But, with Analytical function the same can be made to hit only once. Using this kind of analytical functions is particularly useful when the query needs to be [...]]]></description>
				<content:encoded><![CDATA[
<p>To retrieve Nth row from a table using the usual way it might require to query the same table thrice (can write it in different way also). But, with Analytical function the same can be made to hit only once. Using this kind of analytical functions is particularly useful when the query needs to be part of a huge query &#8211; helps to avoid group by &#8211; so the need to query the same table multiple times is reduced.</p>
<p><span style="font-weight:bold">Non Analytical way</span></p>
<p>One way to do this &#8211; Usual &#8211; three table hits.</p>
<p>select sal FROM scott.emp WHERE rowid = (SELECT rowid FROM scott.emp WHERE rownum &lt;= 5 MINUS SELECT rowid FROM scott.emp WHERE rownum &lt; 5);</p>
<p>SAL<br />
&#8212;&#8212;&#8212;-<br />
1250</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 791824717</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 1 | 16 | 5 (40)| 00:00:01 |<br />
<span style="font-weight:bold">| 1 | TABLE ACCESS BY USER ROWID| EMP | 1 | 16 | 1 (0)| 00:00:01 |</span><br />
| 2 | MINUS | | | | | |<br />
| 3 | SORT UNIQUE | | 5 | 60 | 2 (50)| 00:00:01 |<br />
|* 4 | COUNT STOPKEY | | | | | |<br />
<span style="font-weight:bold">| 5 | INDEX FULL SCAN | PK_EMP | 14 | 168 | 1 (0)| 00:00:01 |</span><br />
| 6 | SORT UNIQUE | | 4 | 48 | 2 (50)| 00:00:01 |<br />
|* 7 | COUNT STOPKEY | | | | | |<br />
<span style="font-weight:bold">| 8 | INDEX FULL SCAN | PK_EMP | 14 | 168 | 1 (0)| 00:00:01 |</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>4 &#8211; filter(ROWNUM&lt;=5)<br />
7 &#8211; filter(ROWNUM&lt;5)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">5 consistent gets</span><br />
0 physical reads<br />
0 redo size<br />
414 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
2 sorts (memory)<br />
0 sorts (disk)<br />
1 rows processed</p>
<p><span style="font-weight:bold">Using Analytical functions<br />
</span></p>
<p>SQL&gt; SELECT a.* FROM<br />
(select e.*,row_number() OVER (order by rownum) rnm FROM scott.emp e) a<br />
WHERE rnm = 5;</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
DEPTNO RNM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400<br />
30 5</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 1602237660</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 1 | VIEW | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 2 | WINDOW SORT PUSHED RANK| | 14 | 518 | 4 (25)| 00:00:01|<br />
| 3 | COUNT | | | | ||<br />
<span style="font-weight:bold">| 4 | TABLE ACCESS FULL | EMP | 14 | 518 | 3 (0)| 00:00:01|</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;RNM&#8221;=5)<br />
2 &#8211; filter(ROW_NUMBER() OVER ( ORDER BY ROWNUM)&lt;=5)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">7 consistent gets<br />
</span>0 physical reads<br />
0 redo size<br />
892 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
1 sorts (memory)<br />
0 sorts (disk)<br />
1 rows processed</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-retrieve-the-nth-row-from-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analytical way &#8211; Retrieve say 5 to 8 rows from table</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-retrieve-say-5-to-8-rows-from-table/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-retrieve-say-5-to-8-rows-from-table/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 15:12:30 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-retrieve-say-5-to-8-rows-from-table/</guid>
		<description><![CDATA[Non-Analytical way SELECT a.* FROM (select e.*,ROWNUM rnm FROM scott.emp e) a WHERE rnm BETWEEN 3 AND 8; SQL&#62; SELECT a.* FROM 2 (select e.*,ROWNUM rnm FROM scott.emp e) a 3 WHERE rnm BETWEEN 3 AND 8; EMPNO ENAME JOB MGR HIREDATE SAL COMM &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- DEPTNO RNM &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- [...]]]></description>
				<content:encoded><![CDATA[
<p><span style="font-weight:bold">Non-Analytical way</span></p>
<p>SELECT a.* FROM<br />
(select e.*,ROWNUM rnm FROM scott.emp e) a<br />
WHERE rnm BETWEEN 3 AND 8;</p>
<p>SQL&gt; SELECT a.* FROM<br />
2 (select e.*,ROWNUM rnm FROM scott.emp e) a<br />
3 WHERE rnm BETWEEN 3 AND 8;</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
DEPTNO RNM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
7521 WARD SALESMAN 7698 22-FEB-81 1250 500<br />
30 3</p>
<p>7566 JONES MANAGER 7839 02-APR-81 2975<br />
20 4</p>
<p>7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400<br />
30 5</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
DEPTNO RNM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
7698 BLAKE MANAGER 7839 01-MAY-81 2850<br />
30 6</p>
<p>7782 CLARK MANAGER 7839 09-JUN-81 2450<br />
10 7</p>
<p>7788 SCOTT ANALYST 7566 19-APR-87 3000<br />
20 8</p>
<p>6 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 2077119879</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| 0 | SELECT STATEMENT | | 14 | 1400 | 3 (0)| 00:00:01 |<br />
|* 1 | VIEW | | 14 | 1400 | 3 (0)| 00:00:01 |<br />
| 2 | COUNT | | | | | |<br />
<span style="font-weight:bold">| 3 | TABLE ACCESS FULL| EMP | 14 | 518 | 3 (0)| 00:00:01 |<br />
</span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;RNM&#8221;=3)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">8 consistent gets</span><br />
0 physical reads<br />
0 redo size<br />
1142 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
0 sorts (memory)<br />
0 sorts (disk)<br />
6 rows processed</p>
<p>SQL&gt;</p>
<p>OR</p>
<p>SELECT * FROM scott.emp WHERE rowid in (SELECT rowid FROM scott.emp WHERE rownum &lt;= 8<br />
MINUS<br />
SELECT rowid FROM scott.emp WHERE rownum &lt; 3);</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30<br />
7566 JONES MANAGER 7839 02-APR-81 2975 20<br />
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30<br />
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30<br />
7782 CLARK MANAGER 7839 09-JUN-81 2450 10<br />
7788 SCOTT ANALYST 7566 19-APR-87 3000 20</p>
<p>6 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 986843382<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 1 | 49 | 8 (38)| 00:00:01|<br />
|* 1 | HASH JOIN | | 1 | 49 | 8 (38)| 00:00:01|<br />
| 2 | VIEW | VW_NSO_1 | 8 | 96 | 4 (50)| 00:00:01|<br />
| 3 | MINUS | | | | ||<br />
| 4 | SORT UNIQUE | | 8 | 96 | ||<br />
|* 5 | COUNT STOPKEY | | | | ||<br />
<span style="font-weight:bold">| 6 | INDEX FULL SCAN| PK_EMP | 14 | 168 | 1 (0)| 00:00:01|</span><br />
| 7 | SORT UNIQUE | | 2 | 24 | ||<br />
|* 8 | COUNT STOPKEY | | | | ||<br />
<span style="font-weight:bold">| 9 | INDEX FULL SCAN| PK_EMP | 14 | 168 | 1 (0)| 00:00:01|<br />
</span><span style="font-weight:bold">| 10 | TABLE ACCESS FULL | EMP | 14 | 518 | 3 (0)| 00:00:01|</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; access(ROWID=&#8221;ROWID&#8221;)<br />
5 &#8211; filter(ROWNUM&lt;=8)<br />
8 &#8211; filter(ROWNUM&lt;3)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">10 consistent gets</span><br />
0 physical reads<br />
0 redo size<br />
1069 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
2 sorts (memory)<br />
0 sorts (disk)<br />
6 rows processed</p>
<p><span style="font-weight:bold">Using Analytical functions<br />
</span></p>
<p>SQL&gt; SELECT a.* FROM<br />
(select e.*,row_number() OVER (order by rownum) rnm FROM scott.emp e) a<br />
WHERE rnm BETWEEN 3 AND 8;</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
DEPTNO RNM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
7521 WARD SALESMAN 7698 22-FEB-81 1250 500<br />
30 3<br />
7566 JONES MANAGER 7839 02-APR-81 2975<br />
20 4<br />
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400<br />
30 5<br />
7698 BLAKE MANAGER 7839 01-MAY-81 2850<br />
30 6<br />
7782 CLARK MANAGER 7839 09-JUN-81 2450<br />
10 7<br />
7788 SCOTT ANALYST 7566 19-APR-87 3000<br />
20 8</p>
<p>6 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 1602237660</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 1 | VIEW | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 2 | WINDOW SORT PUSHED RANK| | 14 | 518 | 4 (25)| 00:00:01|<br />
| 3 | COUNT | | | | ||<br />
| 4 | TABLE ACCESS FULL | EMP | 14 | 518 | 3 (0)| 00:00:01|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;RNM&#8221;&gt;=3 AND &#8220;RNM&#8221;&lt;=8)<br />
2 &#8211; filter(ROW_NUMBER() OVER ( ORDER BY ROWNUM)&lt;=8)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">7 consistent gets</span><br />
0 physical reads<br />
0 redo size<br />
1142 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
1 sorts (memory)<br />
0 sorts (disk)<br />
6 rows processed</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-retrieve-say-5-to-8-rows-from-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analytical way &#8211; TOP N rows from a table</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-top-n-rows-from-a-table/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-top-n-rows-from-a-table/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 15:11:22 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-top-n-rows-from-a-table/</guid>
		<description><![CDATA[Non Analytical way SELECT * FROM scott.emp inside WHERE 5 &#62;= (SELECT COUNT (DISTINCT outside.sal) FROM scott.emp outside WHERE outside.sal &#62;= inside.sal) ORDER BY inside.sal DESC; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;- 7839 KING PRESIDENT 17-NOV-81 5000 10 7902 FORD ANALYST 7566 03-DEC-81 3000 20 [...]]]></description>
				<content:encoded><![CDATA[
<p><span style="font-weight:bold">Non Analytical way</span></p>
<p>SELECT * FROM scott.emp inside WHERE 5 &gt;= (SELECT COUNT (DISTINCT outside.sal) FROM scott.emp outside<br />
WHERE outside.sal &gt;= inside.sal) ORDER BY inside.sal DESC;</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;-<br />
7839 KING PRESIDENT 17-NOV-81 5000 10<br />
7902 FORD ANALYST 7566 03-DEC-81 3000 20<br />
7788 SCOTT ANALYST 7566 19-APR-87 3000 20<br />
7566 JONES MANAGER 7839 02-APR-81 2975 20<br />
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30<br />
7782 CLARK MANAGER 7839 09-JUN-81 2450 10</p>
<p>6 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 1721702769</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 1 | 37 | 25 (4)| 00:00:01 |<br />
| 1 | SORT ORDER BY | | 1 | 37 | 25 (4)| 00:00:01 |<br />
|* 2 | FILTER | | | | | |<br />
<span style="font-weight:bold">| 3 | TABLE ACCESS FULL | EMP | 14 | 518 | 3 (0)| 00:00:01 |</span><br />
| 4 | SORT GROUP BY | | 1 | 4 | | |<br />
<span style="font-weight:bold">|* 5 | TABLE ACCESS FULL| EMP | 1 | 4 | 3 (0)| 00:00:01 |</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; filter( (SELECT COUNT(DISTINCT &#8220;OUTSIDE&#8221;.&#8221;SAL&#8221;) FROM<br />
&#8220;SCOTT&#8221;.&#8221;EMP&#8221; &#8220;OUTSIDE&#8221; WHERE &#8220;OUTSIDE&#8221;.&#8221;SAL&#8221;&gt;=:B1)=:B1)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">91 consistent gets</span><br />
0 physical reads<br />
0 redo size<br />
1028 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
13 sorts (memory)<br />
0 sorts (disk)<br />
6 rows processed</p>
<p>SQL&gt;</p>
<p>Analytical way<br />
SQL&gt; SELECT a.* FROM<br />
2 (select e.*,row_number() OVER (order by rownum) rnm FROM scott.emp e) a<br />
3 WHERE rnm BETWEEN 1 AND 6;</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
DEPTNO RNM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
7369 SMITH CLERK 7902 17-DEC-80 800<br />
20 1<br />
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300<br />
30 2<br />
7521 WARD SALESMAN 7698 22-FEB-81 1250 500<br />
30 3<br />
7566 JONES MANAGER 7839 02-APR-81 2975<br />
20 4<br />
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400<br />
30 5<br />
7698 BLAKE MANAGER 7839 01-MAY-81 2850<br />
30 6</p>
<p>6 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 1602237660</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time|<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 1 | VIEW | | 14 | 1400 | 4 (25)| 00:00:01|<br />
|* 2 | WINDOW SORT PUSHED RANK| | 14 | 518 | 4 (25)| 00:00:01|<br />
| 3 | COUNT | | | | ||<br />
<span style="font-weight:bold">| 4 | TABLE ACCESS FULL | EMP | 14 | 518 | 3 (0)| 00:00:01|</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>-</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;RNM&#8221;&gt;=1 AND &#8220;RNM&#8221;&lt;=6)<br />
2 &#8211; filter(ROW_NUMBER() OVER ( ORDER BY ROWNUM)&lt;=6)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">7 consistent gets</span><br />
0 physical reads<br />
0 redo size<br />
1140 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
1 sorts (memory)<br />
0 sorts (disk)<br />
6 rows processed</p>
<p>SQL&gt;</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-top-n-rows-from-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analytical way &#8211; TO FIND RUNNING TOTAL</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-running-total/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-running-total/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 15:10:58 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-running-total/</guid>
		<description><![CDATA[To find the running total using the non-analytical way minimum the same table needs to be joined twice. Using Analytical functions the same can be achieved with single table hit. In a single query running total can be computed in no time. NON ANALYTICAL WAY - Select emp1.empno, emp1.sal, sum(emp2.sal) from scott.emp emp1, scott.emp emp2 [...]]]></description>
				<content:encoded><![CDATA[
<p>To find the running total using the non-analytical way minimum the same table needs to be joined twice. Using Analytical functions the same can be achieved with single table hit. In a single query running total can be computed in no time.</p>
<p><span style="font-weight:bold">NON ANALYTICAL WAY -</span></p>
<p>Select emp1.empno, emp1.sal, sum(emp2.sal) from scott.emp emp1, scott.emp emp2<br />
where emp2.empno &lt;= emp1.empno group by emp1.empno, emp1.sal<br />
order by emp1.empno</p>
<p>EMPNO SAL SUM(EMP2.SAL)<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;-<br />
7369 800 800<br />
7499 1600 2400<br />
7521 1250 3650<br />
7566 2975 6625<br />
7654 1250 7875<br />
7698 2850 10725<br />
7782 2450 13175<br />
7788 3000 16175<br />
7839 5000 21175<br />
7844 1500 22675<br />
7876 1100 23775<br />
7900 950 24725<br />
7902 3000 27725<br />
7934 1300 29025</p>
<p>14 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 1016356015<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 10 | 160 | 7 (29)| 0<br />
0:00:01 |<br />
| 1 | SORT GROUP BY | | 10 | 160 | 7 (29)| 0<br />
0:00:01 |<br />
| 2 | MERGE JOIN | | 10 | 160 | 6 (17)| 0<br />
0:00:01 |<br />
| 3 | SORT JOIN | | 14 | 112 | 2 (0)| 0<br />
0:00:01 |<br />
| 4 | TABLE ACCESS BY INDEX ROWID| EMP | 14 | 112 | 2 (0)| 0<br />
0:00:01 |<br />
| 5 | INDEX FULL SCAN | PK_EMP | 14 | | 1 (0)| 0<br />
0:00:01 |<br />
|* 6 | SORT JOIN | | 14 | 112 | 4 (25)| 0<br />
0:00:01 |<br />
| 7 | TABLE ACCESS FULL | EMP | 14 | 112 | 3 (0)| 0<br />
0:00:01 |</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>6 &#8211; access(INTERNAL_FUNCTION(&#8220;EMP2&#8243;.&#8221;EMPNO&#8221;)&lt;=INTERNAL_FUNCTION(&#8220;EMP1&#8243;.&#8221;EMPNO<br />
&#8221; )) filter(INTERNAL_FUNCTION(&#8220;EMP2&#8243;.&#8221;EMPNO&#8221;)&lt;=INTERNAL_FUNCTION(&#8220;EMP1&#8243;.&#8221;EMPNO<br />
&#8221; ))</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">9 consistent gets</span><br />
0 physical reads<br />
0 redo size<br />
790 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
3 sorts (memory)<br />
0 sorts (disk)<br />
14 rows processed</p>
<p>SQL&gt;</p>
<p><span style="font-weight:bold">ANALYTICAL WAY</span></p>
<p>SQL&gt; set autotrace on<br />
SQL&gt; Select e1.empno, e1.sal, sum(e1.sal) OVER (ORDER BY rownum) from scott.emp<br />
e1 order by e1.empno;</p>
<p>EMPNO SAL SUM(E1.SAL)OVER(ORDERBYROWNUM)<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
7369 800 800<br />
7499 1600 2400<br />
7521 1250 3650<br />
7566 2975 6625<br />
7654 1250 7875<br />
7698 2850 10725<br />
7782 2450 13175<br />
7788 3000 16175<br />
7839 5000 21175<br />
7844 1500 22675<br />
7876 1100 23775<br />
7900 950 24725<br />
7902 3000 27725<br />
7934 1300 29025</p>
<p>14 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 3990564813</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 14 | 112 | 5 (40)| 00:00:01 |<br />
| 1 | SORT ORDER BY | | 14 | 112 | 5 (40)| 00:00:01 |<br />
| 2 | WINDOW SORT | | 14 | 112 | 5 (40)| 00:00:01 |<br />
| 3 | COUNT | | | | | |<br />
<span style="font-weight:bold">| 4 | TABLE ACCESS FULL| EMP | 14 | 112 | 3 (0)| 00:00:01 |</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">7 consistent gets<br />
</span>0 physical reads<br />
0 redo size<br />
807 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
2 sorts (memory)<br />
0 sorts (disk)<br />
14 rows processed</p>
<p>SQL&gt;</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-running-total/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analytical way &#8211; TO FIND LAST N ROWS AND DISPLAY ROWNUMBER IN A TABLE</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-last-n-rows-and-display-rownumber-in-a-table/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-last-n-rows-and-display-rownumber-in-a-table/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 15:10:13 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-last-n-rows-and-display-rownumber-in-a-table/</guid>
		<description><![CDATA[To find the last N and display the row number. With the usual way to pick last set of records from any table minimum 3 joins are required. Using analytical functions the same can be reduced to single table hit to retrieve the last N rows and display the row numbers for the same. This [...]]]></description>
				<content:encoded><![CDATA[
<p>To find the last N and display the row number.</p>
<p>With the usual way to pick last set of records from any table minimum 3 joins are required. Using analytical functions the same can be reduced to single table hit to retrieve the last N rows and display the row numbers for the same. This is particularly useful when something like this needs to be achieved in a big query that has multiple joins and multiple column fetch.</p>
<p><span style="font-weight:bold">NON ANALYTICAL WAY</span></p>
<p>select * from scott.emp minus select * from scott.emp where rownum select * from scott.emp minus select * from scott.emp where rownum &lt;<br />
2 (select count(*) &#8211; 10 from scott.emp);</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;-<br />
7566 JONES MANAGER 7839 02-APR-81 2975 20<br />
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30<br />
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30<br />
7782 CLARK MANAGER 7839 09-JUN-81 2450 10<br />
7788 SCOTT ANALYST 7566 19-APR-87 3000 20<br />
7839 KING PRESIDENT 17-NOV-81 5000 10<br />
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30<br />
7876 ADAMS CLERK 7788 23-MAY-87 1100 20<br />
7900 JAMES CLERK 7698 03-DEC-81 950 30<br />
7902 FORD ANALYST 7566 03-DEC-81 3000 20<br />
7934 MILLER CLERK 7782 23-JAN-82 1300 10</p>
<p>11 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 2564595189</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| 0 | SELECT STATEMENT | | 14 | 1036 | 9 (67)| 00:00:01 |<br />
| 1 | MINUS | | | | | |<br />
| 2 | SORT UNIQUE | | 14 | 518 | 4 (25)| 00:00:01 |<br />
<span style="font-weight:bold">| 3 | TABLE ACCESS FULL | EMP | 14 | 518 | 3 (0)| 00:00:01 |</span><br />
| 4 | SORT UNIQUE | | 14 | 518 | 5 (20)| 00:00:01 |<br />
|* 5 | COUNT STOPKEY | | | | | |<br />
<span style="font-weight:bold">| 6 | TABLE ACCESS FULL| EMP | 14 | 518 | 3 (0)| 00:00:01 |</span><br />
| 7 | SORT AGGREGATE | | 1 | | | |<br />
<span style="font-weight:bold">| 8 | INDEX FULL SCAN | PK_EMP | 14 | | 1 (0)| 00:00:01 |</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>5 &#8211; filter( (SELECT COUNT(*)-10 FROM &#8220;SCOTT&#8221;.&#8221;EMP&#8221; &#8220;EMP&#8221;)&gt;ROWNUM)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">13 consistent gets</span><br />
0 physical reads<br />
0 redo size<br />
1250 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
2 sorts (memory)<br />
0 sorts (disk)<br />
11 rows processed</p>
<p>SQL&gt;</p>
<p><span style="font-weight:bold">ANALYTICAL WAY</span></p>
<p>SELECT qry.empno, qry.ename, qry.job, qry.mgr, qry.hiredate,qry.sal,qry.comm,qry.deptno,qry.row_desc<br />
from<br />
(SELECT A.*, COUNT(1) OVER (ORDER BY ROWNUM ASC) ROW_ASC, COUNT(1) OVER (ORDER BY ROWNUM DESC) ROW_DESC FROM SCOTT.EMP A) QRY where qry.row_Asc between 1 and 11</p>
<p>SQL&gt; SELECT qry.empno, qry.ename, qry.job, qry.mgr, qry.hiredate,qry.sal,qry.com<br />
m,qry.deptno,qry.row_desc<br />
2 from (SELECT A.*, COUNT(1) OVER (ORDER BY ROWNUM ASC) ROW_ASC, COUNT(1) OVE<br />
R (ORDER BY ROWNUM DESC) ROW_DESC FROM SCOTT.EMP A) QRY where qry.row_Asc betwee<br />
n 1 and 11;</p>
<p>EMPNO ENAME JOB MGR HIREDATE SAL COMM<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
DEPTNO ROW_DESC<br />
&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br />
7876 ADAMS CLERK 7788 23-MAY-87 1100<br />
20 4<br />
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0<br />
30 5<br />
7839 KING PRESIDENT 17-NOV-81 5000<br />
10 6<br />
7788 SCOTT ANALYST 7566 19-APR-87 3000<br />
20 7<br />
7782 CLARK MANAGER 7839 09-JUN-81 2450<br />
10 8<br />
7698 BLAKE MANAGER 7839 01-MAY-81 2850<br />
30 9<br />
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400<br />
30 10<br />
7566 JONES MANAGER 7839 02-APR-81 2975<br />
20 11<br />
7521 WARD SALESMAN 7698 22-FEB-81 1250 500<br />
30 12<br />
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300<br />
30 13<br />
7369 SMITH CLERK 7902 17-DEC-80 800<br />
20 14</p>
<p>11 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 2175649969</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| 0 | SELECT STATEMENT | | 14 | 1582 | 5 (40)| 00:00:01 |<br />
|* 1 | VIEW | | 14 | 1582 | 5 (40)| 00:00:01 |<br />
| 2 | WINDOW SORT | | 14 | 518 | 5 (40)| 00:00:01 |<br />
| 3 | WINDOW SORT | | 14 | 518 | 5 (40)| 00:00:01 |<br />
| 4 | COUNT | | | | | |<br />
<span style="font-weight:bold">| 5 | TABLE ACCESS FULL| EMP | 14 | 518 | 3 (0)| 00:00:01 |</span><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;QRY&#8221;.&#8221;ROW_ASC&#8221;&gt;=1 AND &#8220;QRY&#8221;.&#8221;ROW_ASC&#8221;&lt;=11)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
<span style="font-weight:bold">7 consistent gets<br />
</span>0 physical reads<br />
0 redo size<br />
1360 bytes sent via SQL*Net to client<br />
416 bytes received via SQL*Net from client<br />
2 SQL*Net roundtrips to/from client<br />
2 sorts (memory)<br />
0 sorts (disk)<br />
11 rows processed</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/performance-tuning-to-find-last-n-rows-and-display-rownumber-in-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating from 9i to 11g &#8211; Collections Enhancements</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/migrating-from-9i-to-11g-collections-enhancements/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/migrating-from-9i-to-11g-collections-enhancements/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 12:42:30 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/?p=10</guid>
		<description><![CDATA[1 Indicies of New feature in Oracle 10g. In FORALL collections.FIRST .. collections.LAST it is not possible to use the indices sequntially if the collection is sparse. But, the same can be handled in Oracle 10g by using FORALL IN INDICES OF keyword. create table emp1(empno number, still_employed varchar2(20)) insert into emp1 values (1, &#8216;Y&#8217;); [...]]]></description>
				<content:encoded><![CDATA[
<p><strong>1 Indicies of</strong></p>
<p>New feature in Oracle 10g.</p>
<p>In FORALL collections.FIRST .. collections.LAST it is not possible to use the indices sequntially if the collection is sparse. But, the same can be handled in Oracle 10g by using <em><strong>FORALL IN INDICES OF keyword.</strong></em></p>
<p>create table emp1(empno number, still_employed varchar2(20))</p>
<p>insert into emp1 values (1, &#8216;Y&#8217;);<br />
insert into emp1 values (2, &#8216;N&#8217;);<br />
insert into emp1 values (3, &#8216;Y&#8217;);</p>
<p><strong>Oracle 9i<br />
</strong>SET SERVEROUTPUT ON SIZE 10000<br />
DECLARE<br />
TYPE emp_id_list IS TABLE OF VARCHAR2(100) INDEX BY PLS_INTEGER;<br />
TYPE emp_list IS TABLE OF emp1%ROWTYPE;<br />
emp_id_tab emp_id_list ;<br />
emp_tab emp_list := emp_list();<br />
BEGIN</p>
<p>emp_Tab.extend;<br />
emp_tab(1).empno := 10;<br />
emp_Tab.extend;<br />
emp_tab(2).empno := 100;<br />
emp_Tab.extend;<br />
emp_Tab.extend;<br />
emp_tab(4).empno := 1000;</p>
<p>emp_Tab.extend;<br />
emp_id_tab(1) := &#8216;Y&#8217;;<br />
emp_Tab.extend;<br />
emp_id_tab(2) := &#8216;N&#8217;;<br />
emp_Tab.extend;<br />
emp_Tab.extend;<br />
emp_id_tab(4) := &#8216;Y&#8217;;</p>
<p><strong>FORALL i IN emp_id_tab.first .. emp_id_tab.last<br />
</strong>UPDATE EMP1 SET ROW = emp_tab(i)<br />
WHERE still_employed = emp_id_tab(i);<br />
END;<br />
/</p>
<p><strong>OUTPUT </strong></p>
<p>DECLARE<br />
*<br />
ERROR at line 1:<br />
ORA-22160: element at index [3] does not exist<br />
ORA-06512: at line 24</p>
<p><strong>Oracle 11g<br />
</strong>SET SERVEROUTPUT ON SIZE 10000<br />
DECLARE<br />
TYPE emp_id_list IS TABLE OF VARCHAR2(100) INDEX BY PLS_INTEGER;<br />
TYPE emp_list IS TABLE OF emp1%ROWTYPE;<br />
emp_id_tab emp_id_list ;<br />
emp_tab emp_list := emp_list();<br />
BEGIN</p>
<p>emp_Tab.extend;<br />
emp_tab(1).empno := 10;<br />
emp_Tab.extend;<br />
emp_tab(2).empno := 100;<br />
emp_Tab.extend;<br />
emp_Tab.extend;<br />
emp_tab(4).empno := 1000;</p>
<p>emp_Tab.extend;<br />
emp_id_tab(1) := &#8216;Y&#8217;;<br />
emp_Tab.extend;<br />
emp_id_tab(2) := &#8216;N&#8217;;<br />
emp_Tab.extend;<br />
emp_Tab.extend;<br />
emp_id_tab(4) := &#8216;Y&#8217;;</p>
<p><strong>FORALL i IN INDICES OF emp_id_tab<br />
</strong>UPDATE EMP1 SET ROW = emp_tab(i)<br />
WHERE still_employed = emp_id_tab(i);<br />
END;<br />
/<br />
<strong><br />
OUTPUT </strong></p>
<p>PL/SQL procedure successfully completed.</p>
<p><strong>2 Values of</strong></p>
<p>New feature in Oracle 10g.</p>
<p>VALUES OF clause enables to match the elements of one collection against the value of another collection and helps to perform DML operations based on the same.</p>
<p>DELETE FROM EMP1;</p>
<p><strong>Oracle 9i<br />
</strong>SET SERVEROUTPUT ON SIZE 10000<br />
DECLARE<br />
TYPE emp_id_list IS TABLE OF PLS_INTEGER<br />
INDEX BY PLS_INTEGER;<br />
emp_id_tab emp_id_list;</p>
<p>TYPE emp_list IS TABLE OF emp1%ROWTYPE<br />
INDEX BY PLS_INTEGER;<br />
emp_tab emp_list;<br />
BEGIN</p>
<p>emp_id_tab(1) := 10;<br />
emp_id_tab(2) := 9;<br />
emp_id_tab(3) := 8;</p>
<p>SELECT rownum,&#8217;Y&#8217; BULK COLLECT INTO emp_tab<br />
FROM emp<br />
WHERE ROWNUM &lt;= 50;</p>
<p>FORALL i IN emp_id_tab.FIRST .. emp_id_tab.LAST<br />
INSERT INTO EMP1 VALUES emp_tab(i);<br />
END;<br />
/<br />
<strong><br />
<strong>OUTPUT</strong></strong></p>
<p>PL/SQL procedure successfully completed.</p>
<p>EMPNO STILL_EMPLOYED<br />
1 Y<br />
2 Y<br />
3 Y</p>
<p>Only solution is – create nested table and perform and compare empno against TABLE(nested_table) in SELECT statement.</p>
<p>Oracle 11g<br />
SET SERVEROUTPUT ON SIZE 10000<br />
DECLARE<br />
TYPE emp_id_list IS TABLE OF PLS_INTEGER<br />
INDEX BY PLS_INTEGER;<br />
emp_id_tab emp_id_list;</p>
<p>TYPE emp_list IS TABLE OF emp1%ROWTYPE<br />
INDEX BY PLS_INTEGER;<br />
emp_tab emp_list;<br />
BEGIN</p>
<p>emp_id_tab(1) := 10;<br />
emp_id_tab(2) := 9;<br />
emp_id_tab(3) := 8;</p>
<p>SELECT rownum,&#8217;Y&#8217; BULK COLLECT INTO emp_tab<br />
FROM emp<br />
WHERE ROWNUM &lt;= 50;</p>
<p><strong>FORALL i IN VALUES OF emp_id_tab<br />
</strong>INSERT INTO EMP1 VALUES emp_tab(i);<br />
END;<br />
/<br />
<strong><br />
OUTPUT</strong></p>
<p>PL/SQL procedure successfully completed.</p>
<p>EMPNO STILL_EMPLOYED<br />
10 Y<br />
9 Y<br />
8 Y</p>
<p>If we note the above results, the VALUES OF clause exactly matches the elements of one collection vs the elements of other collection and inserts values. This cannot be achieved in Oracle 9i unless we explicitly match up the elements in the WHERE clause.</p>
<p><strong>3 Error handling</strong></p>
<p><strong>Oracle 9i<br />
</strong>SET SERVEROUTPUT ON SIZE 10000<br />
DECLARE<br />
TYPE emp_id_list IS TABLE OF PLS_INTEGER<br />
INDEX BY PLS_INTEGER;<br />
emp_id_tab emp_id_list;</p>
<p>TYPE emp_list IS TABLE OF emp1%ROWTYPE<br />
INDEX BY PLS_INTEGER;<br />
emp_tab emp_list;<br />
BEGIN</p>
<p>emp_id_tab(1) := 10;<br />
emp_id_tab(2) := 9;<br />
emp_id_tab(3) := 100;</p>
<p>SELECT rownum,&#8217;Y&#8217; BULK COLLECT INTO emp_tab<br />
FROM emp<br />
WHERE ROWNUM &lt;= 50;</p>
<p>FORALL i IN emp_id_tab.FIRST .. emp_id_tab.LAST<br />
INSERT INTO EMP1 VALUES emp_tab(i);</p>
<p>EXCEPTION WHEN OTHERS THEN<br />
dbms_output.put_line(&#8216;Error message &#8216; || SQLERRM);<br />
END;<br />
/<br />
<strong><br />
OUTPUT</strong></p>
<p>PL/SQL procedure successfully completed.<br />
EMPNO STILL_EMPLOYED<br />
1 Y<br />
2 Y<br />
3 Y<br />
This will still work – because it does not try to match the elements.</p>
<p><strong>Oracle 11g<br />
</strong>SET SERVEROUTPUT ON SIZE 10000<br />
DECLARE<br />
TYPE emp_id_list IS TABLE OF PLS_INTEGER<br />
INDEX BY PLS_INTEGER;<br />
emp_id_tab emp_id_list;</p>
<p>TYPE emp_list IS TABLE OF emp1%ROWTYPE<br />
INDEX BY PLS_INTEGER;<br />
emp_tab emp_list;<br />
BEGIN</p>
<p>emp_id_tab(1) := 10;<br />
emp_id_tab(2) := 9;<br />
emp_id_tab(3) := 100;</p>
<p>SELECT rownum,&#8217;Y&#8217; BULK COLLECT INTO emp_tab<br />
FROM emp<br />
WHERE ROWNUM &lt;= 50;</p>
<p>FORALL i IN VALUES OF emp_id_tab<br />
INSERT INTO EMP1 VALUES emp_tab(i);</p>
<p><strong>EXCEPTION WHEN OTHERS THEN<br />
dbms_output.put_line(&#8216;Error message &#8216; || SQLERRM);</strong><br />
END;<br />
/</p>
<p><strong>OUTPUT</strong></p>
<p>Error message ORA-22160: element at index [100] does not exist</p>
<p><strong>4 Collect<br />
</strong>New feature from Oracle 11g Release 1</p>
<p>COLLECT enables to transform rows into columns just based on a single function.</p>
<p>Running it on sql developer -</p>
<p>Oracle 11g<br />
select deptno , <strong>collect</strong>(ename) enm from scott.emp<br />
group by deptno ;<br />
<strong><br />
10 VARCHAR(CLARK,KING,MILLER)<br />
20 VARCHAR(SMITH,FORD,ADAMS,SCOTT,JONES)<br />
30 VARCHAR(ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARD)<br />
</strong></p>
<p>We cannot do something like this !!</p>
<p>SELECT qry.dno, SUBSTR(qry.enm,8) empnm from<br />
(select deptno dno , collect(ename) enm from scott.emp<br />
group by deptno ) qry</p>
<p>Running it on sqlplus with report related command-</p>
<p>SQL&gt; break on deptno skip 1;</p>
<p>SQL&gt; select deptno , collect(ename) as empnm from scott.emp group by deptno ;</p>
<p>Oracle 11g<br />
<strong>DEPTNO EMPNM<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
10 SYSTPi7LdWP3QSeisIuh7s78iIg==(&#8216;CLARK&#8217;, &#8216;KING&#8217;, &#8216;MILLER&#8217;)<br />
20 SYSTPi7LdWP3QSeisIuh7s78iIg==(&#8216;SMITH&#8217;, &#8216;FORD&#8217;, &#8216;ADAMS&#8217;, &#8216;SCOTT&#8217;, &#8216;JONES&#8217;)<br />
30 SYSTPi7LdWP3QSeisIuh7s78iIg==(&#8216;ALLEN&#8217;, &#8216;BLAKE&#8217;, &#8216;MARTIN&#8217;, &#8216;TURNER&#8217;, &#8216;JAMES&#8217;, &#8216;WARD&#8217;)<br />
</strong></p>
<p><strong>5 Collection Assignment</strong></p>
<p>Now, the collections assignment is improved with various additional features viz., multiset union, multiset intersect, multiset distcint etc.,<br />
SET SERVEROUTPUT ON<br />
DECLARE<br />
TYPE software_tab IS TABLE OF VARCHAR2(1000);<br />
soft_list_1 software_tab := software_tab(&#8216;Oracle&#8217;,'C&#8217;,'C#&#8217;,'VB&#8217;,'Sql&#8217;);<br />
soft_list_2 software_tab := software_tab(&#8216;Oracle&#8217;,'C&#8217;,'PHP&#8217;,'Java&#8217;);<br />
soft_list_3 software_tab;</p>
<p>BEGIN<br />
&#8211; this is as usual<br />
soft_list_3 := soft_list_1;<br />
FOR i IN soft_list_3.first .. soft_list_3.last LOOP<br />
DBMS_OUTPUT.put_line(&#8216;Assignment eg &#8216; || soft_list_3(i));<br />
END LOOP;</p>
<p>soft_list_3 := soft_list_1 <strong>MULTISET UNION DISTINCT</strong> soft_list_2;<br />
FOR i IN soft_list_3.first .. soft_list_3.last LOOP<br />
DBMS_OUTPUT.put_line(&#8216;Multiset union distinct eg &#8216; || soft_list_3(i));<br />
END LOOP;</p>
<p>soft_list_3 := soft_list_1 <strong>MULTISET INTERSECT DISTINCT</strong> soft_list_2;<br />
FOR i IN soft_list_3.first .. soft_list_3.last LOOP<br />
DBMS_OUTPUT.put_line(&#8216;Multiset intersect distinct eg &#8216; || soft_list_3(i));<br />
END LOOP;</p>
<p>soft_list_3 := soft_list_1<strong> MULTISET EXCEPT </strong>soft_list_2;<br />
FOR i IN soft_list_3.first .. soft_list_3.last LOOP<br />
DBMS_OUTPUT.put_line(&#8216;Multiset except eg &#8216; || soft_list_3(i));<br />
END LOOP;</p>
<p>soft_list_3 := soft_list_1 <strong>MULTISET INTERSECT </strong>soft_list_2;<br />
FOR i IN soft_list_3.first .. soft_list_3.last LOOP<br />
DBMS_OUTPUT.put_line(&#8216;Multiset intersect eg &#8216; || soft_list_3(i));<br />
END LOOP;</p>
<p>soft_list_3 := soft_list_1 <strong>MULTISET EXCEPT DISTINCT</strong> soft_list_2;<br />
FOR i IN soft_list_3.first .. soft_list_3.last LOOP<br />
DBMS_OUTPUT.put_line(&#8216;Multiset except distinct eg &#8216; || soft_list_3(i));<br />
END LOOP;</p>
<p>soft_list_3 := soft_list_1 <strong>MULTISET UNION</strong> soft_list_2;<br />
FOR i IN soft_list_3.first .. soft_list_3.last LOOP<br />
DBMS_OUTPUT.put_line(&#8216;Multiset union eg &#8216; || soft_list_3(i));<br />
END LOOP;<br />
END;<br />
/<br />
<strong>OUTPUT-<br />
Assignment eg Oracle<br />
Assignment eg C<br />
Assignment eg C#<br />
Assignment eg VB<br />
Assignment eg Sql<br />
Multiset union distinct eg Oracle<br />
Multiset union distinct eg C<br />
Multiset union distinct eg C#<br />
Multiset union distinct eg VB<br />
Multiset union distinct eg Sql<br />
Multiset union distinct eg PHP<br />
Multiset union distinct eg Java<br />
Multiset intersect distinct eg Oracle<br />
Multiset intersect distinct eg C<br />
Multiset except eg C#<br />
Multiset except eg VB<br />
Multiset except eg Sql<br />
Multiset intersect eg Oracle<br />
Multiset intersect eg C<br />
Multiset except distinct eg C#<br />
Multiset except distinct eg VB<br />
Multiset except distinct eg Sql<br />
Multiset union eg Oracle<br />
Multiset union eg C<br />
Multiset union eg C#<br />
Multiset union eg VB<br />
Multiset union eg Sql<br />
Multiset union eg Oracle<br />
Multiset union eg C<br />
Multiset union eg PHP<br />
Multiset union eg Java<br />
PL/SQL procedure successfully completed.<br />
Elapsed: 00:00:00.07</strong></p>
<p><strong>6 Improved comparisons</strong></p>
<p>SET SERVEROUTPUT ON<br />
DECLARE<br />
TYPE software_tab IS TABLE OF VARCHAR2(10);<br />
software_list_1 software_tab := software_tab(&#8216;Oracle&#8217;,'C&#8217;,'C#&#8217;,'VB&#8217;,'Sql&#8217;);<br />
software_list_2 software_tab := software_tab(&#8216;Oracle&#8217;,'C&#8217;,'PHP&#8217;,'Java&#8217;);<br />
software_list_3 software_tab;<br />
BEGIN<br />
IF (software_list_3 IS NULL) AND (software_list_1 IS NOT NULL) THEN<br />
DBMS_OUTPUT.put_line(&#8216;Value &#8211; list3 is null and list1 is not null&#8217;);<br />
END IF;<br />
software_list_3 := software_list_1;<br />
IF (software_list_3 = software_list_1) AND (software_list_3 != software_list_2) THEN<br />
DBMS_OUTPUT.put_line(&#8216;list3 = list1 and list3 != list2 &#8216;);<br />
END IF;</p>
<p>IF (SET(software_list_2) <strong>SUBMULTISET</strong> software_list_1) AND (software_list_1 NOT SUBMULTISET software_list_2) THEN<br />
DBMS_OUTPUT.put_line( &#8216;list2 submultiset of list1 and list1 is not sub multiset of list2&#8242;);<br />
END IF;</p>
<p>DBMS_OUTPUT.put_line(&#8216;Duplicates related print list 2 -&#8217; || CARDINALITY(software_list_2));</p>
<p>DBMS_OUTPUT.put_line( &#8216;Remove duplicates list2 &#8211; &#8216; || CARDINALITY(SET(software_list_2)) || &#8216; &#8211; Remove duplicates&#8217;);</p>
<p>IF software_list_2 IS NOT A SET THEN<br />
DBMS_OUTPUT.put_line( &#8216;software_list_2 has duplicates&#8217;);<br />
END IF;</p>
<p>IF software_list_3 <strong>IS NOT EMPTY</strong> THEN<br />
DBMS_OUTPUT.put_line( &#8216;List3 is not empty&#8217;);<br />
END IF;<br />
END;<br />
/<br />
<strong>OUTPUT-<br />
Value &#8211; list3 is null and list1 is not null<br />
list3 = list1 and list3 != list2<br />
Duplicates related print list 2 -4<br />
Remove duplicates list2 &#8211; 4 &#8211; Remove duplicates<br />
List3 is not empty<br />
PL/SQL procedure successfully completed.<br />
Elapsed: 00:00:00.01<br />
</strong></p>
<p><strong>7 Improved SET operator<br />
</strong>Normal assignment assigns all the values including duplicates – SET assignment removes the duplicates before assignment.</p>
<p>SET SERVEROUTPUT ON<br />
DECLARE<br />
TYPE software_tab IS TABLE OF VARCHAR2(10);<br />
software_list_1 software_tab := software_tab(&#8216;Oracle&#8217;,'C&#8217;,'C#&#8217;,'VB&#8217;,'Sql&#8217;, &#8216;Oracle&#8217;,'Sql&#8217;);<br />
software_list_2 software_tab;</p>
<p>BEGIN<br />
software_list_2 := software_list_1;<br />
FOR i IN software_list_2.first .. software_list_2.last LOOP<br />
DBMS_OUTPUT.put_line(&#8216;normal Assignment &#8211; &#8216; || software_list_2(i));<br />
END LOOP;</p>
<p>software_list_2 := SET(software_list_1);<br />
FOR i IN software_list_2.first .. software_list_2.last LOOP<br />
DBMS_OUTPUT.put_line(&#8216;set assignment &#8211; &#8216; || software_list_2(i));<br />
END LOOP;</p>
<p>END;<br />
/<br />
<strong>OUTPUT-<br />
normal Assignment &#8211; Oracle<br />
normal Assignment &#8211; C<br />
normal Assignment &#8211; C#<br />
normal Assignment &#8211; VB<br />
normal Assignment &#8211; Sql<br />
normal Assignment &#8211; Oracle<br />
normal Assignment &#8211; Sql<br />
set assignment &#8211; Oracle<br />
set assignment &#8211; C<br />
set assignment &#8211; C#<br />
set assignment &#8211; VB<br />
set assignment &#8211; Sql<br />
PL/SQL procedure successfully completed.<br />
Elapsed: 00:00:00.04</strong></p>
<p>References : From internet.</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/migrating-from-9i-to-11g-collections-enhancements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating from 9i to 11g &#8211; Adaptive cursor sharing</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle/migrating-from-9i-to-11g-adaptive-cursor-sharing/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle/migrating-from-9i-to-11g-adaptive-cursor-sharing/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 12:19:16 +0000</pubDate>
		<dc:creator>Lakshmi Venkatesh</dc:creator>
		
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle/?p=6</guid>
		<description><![CDATA[Feature available from : Oracle 11g Release 1 Cursor_Sharing enables to notice similar SQL statements that are already parsed and available in SQL area. When the query is issued for the first time, the same is stored in the SQL area. Later, on issuing same / similar SQL statements, the query in the memory would [...]]]></description>
				<content:encoded><![CDATA[
<p><strong>Feature available from : Oracle 11g Release 1</strong></p>
<p>Cursor_Sharing enables to notice similar SQL statements that are already parsed and available in SQL area. When the query is issued for the first time, the same is stored in the SQL area. Later, on issuing same / similar SQL statements, the query in the memory would be processed – parsing will not take place again. Default cursor sharing parameter is EXACT. Only if the SQL statement is exactly similar the query will be used otherwise it will be parsed again.</p>
<p>Setting cursor_sharing to FORCE or SIMILAR enables similar statements to share the SQL.<br />
FORCE – forces similar SQL statements to share the SQL area, detoriating the explain plans.<br />
SIMILAR &#8211; similar SQL statements to share the SQL area, without detoriating the explain plans.<br />
EXACT – only exact SQL statements share the SQL area. This is the default value.</p>
<p>Caution: Setting CURSOR_SHARING to FORCE or SIMILAR prevents any outlines generated with literals from being used if they were generated with CURSOR_SHARING set to EXACT.</p>
<p>All the above three modes will work similarly for bind variables and literals. This results in bind variable peaking problem &#8211; it will choose the same explain plan however the data is distributed without considering the percentage of data returned by the predicate.</p>
<p>Oracle 11g has introduced a new feature adaptive cursor sharing to to choose different plan for queries containing bind variables on skewed data .</p>
<p><strong>1. Literals </strong></p>
<p>create index emp_idx1 on emp (deptno)</p>
<p>exec dbms_stats.gather_index_stats(ownname =&gt; &#8216;SYSTEM&#8217;, indname =&gt; &#8216;emp_idx1&#8242;)</p>
<p>exec dbms_stats.gather_table_stats ( ownname =&gt; &#8216;SYSTEM&#8217;, tabname =&gt; &#8216;EMP&#8217;, method_opt =&gt; &#8216;for all indexed columns size skewonly&#8217;, cascade =&gt; TRUE );</p>
<p><strong>Oracle 9i<br />
</strong></p>
<p>SQL&gt; Select * from emp where deptno = 630;</p>
<p>500 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 3085206398<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| 0 | SELECT STATEMENT | | 8108 | 356K | 118 (0)| 00:00:02 |<br />
| 1 | TABLE ACCESS BY INDEX ROWID | EMP | 8108 | 356K | 118 (0)| 00:00:02 |<br />
<strong>|* 2 | INDEX RANGE SCAN | EMP_IDX1 | 8108 | | 17 (0)| 00:00:01 |<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; access(&#8220;DEPTNO&#8221;=630)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
79 consistent gets<br />
0 physical reads<br />
0 redo size<br />
31937 bytes sent via SQL*Net to client<br />
779 bytes received via SQL*Net from client<br />
35 SQL*Net roundtrips to/from client<br />
0 sorts (memory)<br />
0 sorts (disk)<br />
500 rows processed</p>
<p>Select * from emp where deptno = 550</p>
<p>23929 rows selected.</p>
<p>Elapsed: 00:00:00.29</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 3085206398<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| 0 | SELECT STATEMENT | | 8108 | 356K| 118 (0)| 00:00:02 |<br />
| 1 | TABLE ACCESS BY INDEX ROWID | EMP | 8108 | 356K| 118 (0)| 00:00:02 |<br />
<strong>|* 2 | INDEX RANGE SCAN | EMP_IDX1 | 8108 | | 17 (0)| 00:00:01 |<br />
</strong><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; access(&#8220;DEPTNO&#8221;=550)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
3517 consistent gets<br />
0 physical reads<br />
0 redo size<br />
1564144 bytes sent via SQL*Net to client<br />
17961 bytes received via SQL*Net from client<br />
1597 SQL*Net roundtrips to/from client<br />
0 sorts (memory)<br />
0 sorts (disk)<br />
23929 rows processed</p>
<p>Note: For both the cases INDEX scan was performed.</p>
<p><strong>Oracle 11g<br />
</strong><em></em></p>
<p>alter session set “_optimizer_adaptive_cursor_sharing”=true</p>
<p>SQL&gt; Select * from emp where deptno = 630;</p>
<p>500 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 3085206398<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
| 0 | SELECT STATEMENT | | 517 | 25333 | 9 (0)| 00:00:01 |<br />
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 517 | 25333 | 9 (0)|00:00:01 |<br />
<strong>|* 2 | INDEX RANGE SCAN | EMP_IDX1 | 517 | | 2 (0)| 00:00:01|<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>2 &#8211; access(&#8220;DEPTNO&#8221;=630)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
79 consistent gets<br />
0 physical reads<br />
0 redo size<br />
31937 bytes sent via SQL*Net to client<br />
779 bytes received via SQL*Net from client<br />
35 SQL*Net roundtrips to/from client<br />
0 sorts (memory)<br />
0 sorts (disk)<br />
500 rows processed</p>
<p>alter session set “_optimizer_adaptive_cursor_sharing”=true</p>
<p>Select * from emp where deptno = 550</p>
<p>SQL&gt; Select * from emp where deptno = 550;</p>
<p>23929 rows selected.</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 3956160932<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 23977 | 1147K| 143 (1) | 00:00:02|<br />
<strong>|* 1 | TABLE ACCESS FULL| EMP | 23977 | 1147K| 143 (1)| 00:00:02|<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; filter(&#8220;DEPTNO&#8221;=550)</p>
<p>Statistics<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
1 recursive calls<br />
0 db block gets<br />
2099 consistent gets<br />
0 physical reads<br />
0 redo size<br />
1272097 bytes sent via SQL*Net to client<br />
17961 bytes received via SQL*Net from client<br />
1597 SQL*Net roundtrips to/from client<br />
0 sorts (memory)<br />
0 sorts (disk)<br />
23929 rows processed</p>
<p>With adaptive cursor sharing for the first query retrieving 500 records index scan; second query where 23929 records were fetched – FTS was performed.</p>
<p><strong>2. Bind Variable Peeking</strong></p>
<p>There could be columns with heavily skewed data or otherwise. It should be the case that heavily skewed data should use a different execution plan as opposed to normal data.</p>
<p>If a query needs to be tuned that has bind variable peeking issue then, we can deactivate bind peeking. It uses bind-aware cursor sharing.<br />
Adaptive cursor sharing is the solution for bind variable peeking problem. It only shares the plan only if bind variables are equal. If the bind variables are equal and falls within the range then, it uses the same plan. If the bind values are not equivalent then it creates a new plan.</p>
<p><strong>Oracle 9i<br />
</strong><br />
variable l_value number<br />
exec :l_value := 5</p>
<p>SQL&gt; Select * from test_bind where a = :l_value;<br />
Elapsed: 00:00:00.00</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 317434058</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| 0 | SELECT STATEMENT | | 11 | 33 | 1 (0)| 00:00:01 |<br />
<strong>|* 1 | INDEX RANGE SCAN| A_IDX1 | 11 | 33 | 1 (0)| 00:00:01 |<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; access(&#8220;A&#8221;=TO_NUMBER(:L_VALUE))<br />
variable l_value number<br />
exec :l_value := 501</p>
<p>Select * from test_bind where a = :l_value;</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Plan hash value: 317434058</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
| 0 | SELECT STATEMENT | | 11 | 33 | 1 (0)| 00:00:01 |<br />
<strong>|* 1 | INDEX RANGE SCAN| A_IDX1 | 11 | 33 | 1 (0)| 00:00:01 |<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Predicate Information (identified by operation id):<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>1 &#8211; access(&#8220;A&#8221;=TO_NUMBER(:L_VALUE))</p>
<p><strong><strong>Notes:</strong> In the above example even though the SQL returned more than 40% of data it goes for RANGE SCAN &#8211; just reuses the same plan.<br />
</strong><br />
<strong>Oracle 11g<br />
</strong>CREATE TABLE bind_test (<br />
object_id NUMBER,<br />
object_type varchar2(100),<br />
CONSTRAINT bind_test_pk PRIMARY KEY (object_id));</p>
<p>CREATE INDEX bind_test_idx ON bind_test(object_type);</p>
<p>BEGIN<br />
FOR cur IN (select dummy_seq.nextval id, object_type from all_objects) LOOP<br />
INSERT INTO bind_test VALUES (cur.id, cur.object_type);<br />
end loop;<br />
COMMIT;<br />
END;<br />
/</p>
<p>EXEC DBMS_STATS.gather_table_stats(USER, &#8216;bind_test&#8217;, method_opt=&gt;&#8217;for all indexed columns size skewonly&#8217;, cascade=&gt;TRUE);</p>
<p>alter session set “_optimizer_adaptive_cursor_sharing”=true<br />
ALTER SESSION SET &#8220;_optim_peek_user_binds&#8221;=FALSE;</p>
<p>set autotrace traceonly</p>
<p>VARIABLE l_obj_type VARCHAR2(100)<br />
EXEC :l_obj_type := &#8216;EDITION&#8217;</p>
<p>SELECT COUNT(object_id) FROM bind_test where object_type = :l_obj_type</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 1 | 9 | 9 (0)| 00:00:01 |<br />
| 1 | SORT AGGREGATE | | 1 | 9 | | |<br />
<strong>|* 2 | INDEX RANGE SCAN| BIND_TEST_IDX | 1781 | 16029 | 9 (0)| 00:00:01 |<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>VARIABLE l_obj_type VARCHAR2(100)<br />
EXEC :l_obj_type := &#8216;PACKAGE&#8217;</p>
<p>SELECT COUNT(object_id) FROM bind_test where object_type = :l_obj_type</p>
<p>Execution Plan<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
| 0 | SELECT STATEMENT | | 1 | 9 | 51 (2)| 00:00:01 |<br />
| 1 | SORT AGGREGATE | | 1 | 9 | | |<br />
<strong>|* 2 | TABLE ACCESS FULL| BIND_TEST | 1781 | 16029 | 51 (2)| 00:00:01 |<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle/migrating-from-9i-to-11g-adaptive-cursor-sharing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
