<?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>天道酬勤 &#187; plan</title>
	<atom:link href="http://www.ochef.net/tag/plan/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ochef.net</link>
	<description>Oracle and My Life</description>
	<lastBuildDate>Mon, 09 Jan 2012 05:39:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SQL的执行计划</title>
		<link>http://www.ochef.net/2009/03/sql-implementation-plan.html</link>
		<comments>http://www.ochef.net/2009/03/sql-implementation-plan.html#comments</comments>
		<pubDate>Thu, 19 Mar 2009 05:55:24 +0000</pubDate>
		<dc:creator>ochef</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[plan]]></category>

		<guid isPermaLink="false">http://www.ochef.net/?p=228</guid>
		<description><![CDATA[今天有开发人员问怎么安装SQL的执行计划。配置方法不止一种，下面俺简单说一下方法： 第一种方法如下： 在sys用户下运行如下脚本： SQL&#62;@$ORACLE_HOME/sqlplus/admin/plustrce.sql; 在产生角色plustrace后在sys用户下把该角色授予一般用户username, SQL&#62;grant plustrace to username; 如果愿意，可以把grant命令中的username替换为public。 第二种方法如下： 在sys用户下运行如下脚本： SQL&#62;@$ORACLE_HOME/rdbms/admin/utlxplan.sql; 创建一个plan_table,用来存储分析SQL的结果 SQL&#62;create public synonym plan_table for plan_table; SQL&#62;grant all on plan_table to public; 通过将plan_table设置为public,任何人都可以使用SQL*Plus来查看执行计划，同时也可以把grant to public中的public替换为某个username。 一些开关语句如下： set time on&#124;off 打开时间显示。 set timing on&#124;off 打开显示执行的时间。 set autotrace on&#124;off 打开自动分析，并显示SQL的运行结果。 set autotrace on statistics 按常规执行，只显示SQL的执行统计数据。 set autotrace on explain 按常规运行，只显示优化程序的执行情况。 set autotrace traceonly [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F12%2Foracle-sql-developer-2-1-released.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fsql-implementation-plan.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Oracle SQL Developer 2.1 Released</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F04%2Foracle-buys-sun.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fsql-implementation-plan.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Oracle Buys Sun</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F09%2Fdb2_vs_oracle_01.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fsql-implementation-plan.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DB2对比Oracle学习系列之:instance &amp; database concepts</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fsql-implementation-plan.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Stop and remove oracle advanced replication</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>今天有开发人员问怎么安装SQL的执行计划。配置方法不止一种，下面俺简单说一下方法：</p>
<p>第一种方法如下：</p>
<p>在sys用户下运行如下脚本：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt;@$ORACLE_HOME/sqlplus/admin/plustrce.sql;</pre></div></div>

<p>在产生角色plustrace后在sys用户下把该角色授予一般用户username,</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt;grant plustrace to username;</pre></div></div>

<p>如果愿意，可以把grant命令中的username替换为public。</p>
<p>第二种方法如下：<br />
在sys用户下运行如下脚本：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt;@$ORACLE_HOME/rdbms/admin/utlxplan.sql;</pre></div></div>

<p>创建一个plan_table,用来存储分析SQL的结果</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt;create public synonym plan_table for plan_table;
SQL&gt;grant all on plan_table to public;</pre></div></div>

<p>通过将plan_table设置为public,任何人都可以使用SQL*Plus来查看执行计划，同时也可以把grant to public中的public替换为某个username。</p>
<p>一些开关语句如下：</p>
<blockquote><p><span style="color: #000080;">set time on|off </span> 打开时间显示。</p>
<p><span style="color: #000080;">set timing on|off </span> 打开显示执行的时间。</p>
<p><span style="color: #000080;">set autotrace on|off </span> 打开自动分析，并显示SQL的运行结果。</p>
<p><span style="color: #000080;">set autotrace on statistics</span> 按常规执行，只显示SQL的执行统计数据。</p>
<p><span style="color: #000080;">set autotrace on explain</span> 按常规运行，只显示优化程序的执行情况。</p>
<p><span style="color: #000080;">set autotrace traceonly</span> 打开自动分析统计，不显示SQL的运行结果。</p>
<p><span style="color: #000080;">set autotrace traceonly statistics </span><br />
与set autotrace traceonly一样，不显示执行计划，只显示统计数据。</p>
<p><span style="color: #000080;">set autotrace traceonly explain </span><br />
与set autotrace traceonly一样，不显示统计数据，只显示执行计划。它只对该查询进行分析和解释，INSERT、UPDATE、DELETE和MEGRE都用此方法，只有SELECTE 有所不同。</p></blockquote>
<p>三、示例<br />
<span id="more-228"></span></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt;set timing on
SQL&gt;explain plan for
  2  select * from emp;
&nbsp;
Explained.
&nbsp;
Elapsed: 00:00:00.00
SQL&gt;select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
&nbsp;
--------------------------------------------------------------------
| Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
--------------------------------------------------------------------
|   0 | SELECT STATEMENT     |             |    14 |   518 |     7 |
|   1 |  TABLE ACCESS FULL   | EMP         |    14 |   518 |     7 |
--------------------------------------------------------------------
&nbsp;
Note: cpu costing is off
&nbsp;
9 rows selected.
&nbsp;
Elapsed: 00:00:00.18
SQL&gt;</pre></div></div>

<p class="MsoNormal"><span lang="EN-US">btw：9i与10g的plan table是有区别的，<a href="http://www.oracleblog.cn/study-note/explan-table-between-9i-and-10g/" target="_blank">小荷这里</a>有更详细的测试。</span></p>
<p class="MsoNormal"><span lang="EN-US">Updated @ 02-04-09<br />
</span></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F12%2Foracle-sql-developer-2-1-released.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fsql-implementation-plan.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Oracle SQL Developer 2.1 Released</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F04%2Foracle-buys-sun.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fsql-implementation-plan.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Oracle Buys Sun</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F09%2Fdb2_vs_oracle_01.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fsql-implementation-plan.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">DB2对比Oracle学习系列之:instance &amp; database concepts</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fstop-and-remove-oracle-advanced-replication.html&from=http%3A%2F%2Fwww.ochef.net%2F2009%2F03%2Fsql-implementation-plan.html">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Stop and remove oracle advanced replication</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.ochef.net/2009/03/sql-implementation-plan.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

