<?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>ORATraining Blog &#187; Database Performance Tuning</title>
	<atom:link href="http://www.oratraining.com/blog/category/oracle/database/database-performance-tuning/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oratraining.com/blog</link>
	<description>Not just another Oracle Blog</description>
	<lastBuildDate>Tue, 07 Feb 2012 06:27:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Oracle SQL tuning tips</title>
		<link>http://www.oratraining.com/blog/2009/06/oracle-sql-tuning-tips/</link>
		<comments>http://www.oratraining.com/blog/2009/06/oracle-sql-tuning-tips/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 05:21:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database Performance Tuning]]></category>
		<category><![CDATA[Database programming]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[Oracle DBA]]></category>
		<category><![CDATA[Oracle developers]]></category>
		<category><![CDATA[Oracle PL/SQL]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[performance tuning]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL tuning]]></category>
		<category><![CDATA[sqlplus]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tuning]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.oratraining.com/blog/?p=176</guid>
		<description><![CDATA[Tweet Oracle SQL Tuning Tips consideration when writing an SQL statement is that it returns a correct result. The second is that it be the most efficient for a given situation.  You can use many different SQL statements to achieve the same result. It is often the case that only one statement will be the [...]]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.oratraining.com%2Fblog%2F2009%2F06%2Foracle-sql-tuning-tips%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.oratraining.com/blog/2009/06/oracle-sql-tuning-tips/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.oratraining.com/blog/2009/06/oracle-sql-tuning-tips/"  data-text="Oracle SQL tuning tips" data-count="horizontal">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://www.oratraining.com/blog/2009/06/oracle-sql-tuning-tips/" data-counter="right"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><h2>Oracle SQL Tuning Tips</h2>
<p>consideration when writing an SQL statement is that it returns a correct result. The second is that it be the most efficient for a given situation.  You can use many different SQL statements to achieve the same result. It is often the case that only one statement will be the most efficient choice in a given situation.</p>
<p>Remember that processing SQL is a sequence of Parse (syntax check and object resolution), Execution (required reads and writes), and Fetch (row results retrieved, listed, sorted, and returned). SQL &#8220;tuning&#8221; consists, quite simply, of reducing one or more of them.</p>
<p>Note: generally Parse is the greatest time and resource hog. Parse overhead can be minimized by the use of Procedures, Functions, Packages, Views, etc.</p>
<p>Inadequate performance can have a significant cost impact on your business. A poor performing system and application can result in customer dissatisfaction, reduced productivity, and high costs. It is absolutely critical that the system&#8217;s performance is operating at its peak levels.</p>
<p>Following are some general tips that often increase SQL statement efficiency. Being general they may not apply to a particular scenario.<span id="more-176"></span></p>
<ul>
<li>Tuning SQL should only be done after your code is working correctly. Be aware that there is an inevitable tug-of-war between writing efficient SQL and understandable SQL.</li>
<li>Ensure repeated SQL statements are written<em>absolutely identically</em>to facilitate efficient reuse: re-parsing can often be avoided for each subsequent use of an identical statement.<br />
Writing best practices: all SQL verbs in upper-case i.e. SELECT; separate all words with a single space; all SQL verbs begin on a new line; SQL verbs aligned right or left within the initial verb; set and maintain a table alias standard; use table aliases and when a query involves more than one table prefix all column names with their aliases. Whatever you do, be consistent.</li>
<li>o Use bind variables: The values of bind variables do not need to be the same for two statements to be considered identical. Bind variables are not substituted until a statement has been successfully parsed.</li>
<li>o Use standard approach to table aliases. If two identical SQL statements vary because an identical table has two different aliases, then the SQL is different and will not be re-use or shared.</li>
<li>o Use table aliases and prefix all column names by their aliases when more than one table is involved in a query. This reduces parse time and prevents future syntax errors if someone adds a column to one of the tables with same name as a column in another table. (ORA-00918: COLUMN AMBIGUOUSLY DEFINED)</li>
<li>Code the query as simply as possible i.e. no unnecessary columns are selected, no unnecessary GROUP BY or ORDER BY.<br />
It is the same or faster to SELECT by actual column name(s). The larger the table the more likely the savings.<br />
<em>Use:</em><br />
<em>SELECT customer_id, last_name, first_name, street, city FROM customer;<br />
Rather than, </em><em><br />
SELECT * FROM customer;</em></li>
<li>Beware of WHERE clauses which do not use indexes at all. Even if there is an index over a column that is referenced by a WHERE clause included in this section, Oracle will ignore the index. All these WHERE clause can be re-written to use an index while returning the same values. In other words, Do not perform operations on database objects referenced in the WHERE clause:<br />
<em>Use:<br />
</em><em>SELECT client, date, amount FROM sales WHERE amount <strong>&gt; 0;</strong></em><em><br />
Rather than:<br />
</em><em>SELECT client, date, amount FROM sales WHERE amount <strong>!= 0;<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Use:<br />
SELECT account_name, trans_date, amount FROM transaction WHERE account_name <strong>LIKE &#8216;CAPITAL%&#8217;;</strong><br />
</em><em>Rather than:</em><em><br />
SELECT account_name, trans_date, amount FROM transaction WHERE <strong>SUBSTR(account_name,1,7)=</strong>&#8216;CAPITAL&#8217;;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Use:<br />
SELECT account_name, trans_date, amount FROM transaction WHERE amount <strong>&gt; 0;<br />
</strong></em><em>Rather than:<br />
</em><em>SELECT account_name, trans_date, amount FROM transaction WHERE amount <strong>NOT=0;<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<strong><br />
</strong>Use:<br />
SELECT account_name, trans_date, amount FROM transaction WHERE<strong> amount &lt; 2000;<br />
</strong>Rather than:<br />
SELECT account_name, trans_date, amount FROM transaction WHERE <strong>amount + 3000 </strong>&lt; 5000;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Use:<br />
SELECT account_name, trans_date, amount FROM transaction WHERE <strong>account_name = &#8216;AMEX&#8217; AND account_type = &#8216;A&#8217;;<br />
</strong>Rather than:<br />
SELECT account_name, trans_date, amount FROM transaction WHERE <strong>account_name|| account_type=</strong>&#8216;AMEXA&#8217;; </em></li>
<li>Don&#8217;t forget to tune views. Views are SELECT statements and can be tuned in just the same way as any other type of SLECT statement can be. All tuning applicable to any SQL statement are equally applicable to views.</li>
<li>Avoid including a HAVING clause in SELECT statements. The HAVING clause filters selected rows only after all rows have been fetched. Using a WHERE clause helps reduce overheads in sorting, summing, etc. HAVING clauses should only be used when columns with summary operations applied to them are restricted by the clause.<br />
<em>Use:</em><br />
<em>SELECT city FROM country <strong>WHERE</strong> city!= &#8216;Vancouver&#8217; AND city!= &#8216;Toronto&#8217;; GROUP BY city;</em><em><br />
Rather than:<br />
</em><em>SELECT city FROM country GROUP BY city <strong>HAVING</strong> city!= &#8216;Vancouver&#8217; AND city!= &#8216;Toronto&#8217;;</em></li>
<li>Minimize the number of table lookups (subquery blocks) in queries, particularly if our statements include subquery SELECTs or multicolumn UPDATEs.<br />
<em>Use:<br />
SELECT emp_name FROM emp WHERE <strong>(emp_cat, sal_range</strong>) = (<strong>SELECT</strong> MAX(category), MAX(sal_range) FROM emp_categories) AND emp_dept = 0020;<br />
Rather than:<br />
SELECT emp_name FROM emp WHERE <strong>emp_cat</strong>=(<strong>SELECT</strong> MAX(category) FROM emp_categories) AND <strong>emp_range</strong> = (<strong>SELECT</strong> MAX(sal_range) FROM emp_categories) AND emp_dept = 0020;</em></li>
<li>When writing a sub-query (a SELECT statement within the WHERE or HAVING clause of another SQL statement):</li>
<li>o Use a correlated (refers to at least one value from the outer query) sub-query when the return is relatively small and/or other criteria are efficient i.e. if the tables within the sub-query have efficient indexes.</li>
<li>o Use a non-correlated (does not refer to the outer query) sub-query when dealing with large tables from which you expect a large return (many rows) and/or if the tables within the sub-query do not have efficient indexes.</li>
<li>o Ensure that multiple sub-queries are in the most efficient order.</li>
<li>o Remember that rewriting a sub-query as a join can sometimes increase efficiency.</li>
<li>When doing multiple table joins consider the benefits/costs for each of EXISTS, IN, and table joins. Depending on your data one or another may be faster.<br />
Note: IN is usually the slowest.<br />
Note: When most of the filter criteria are in the sub-query IN may be more efficient; when most of the filter criteria are in the parent-query EXISTS may be more efficient.<em><br />
The following queries return the employee names from each department in department category &#8216;A&#8217;:</em><br />
<em>SELECT emp_name FROM emp E WHERE <strong>EXISTS </strong>(SELECT &#8216;X&#8217; FROM dept WHERE dept_no = E.dept_no AND dept_cat = &#8216;A&#8217;);</em><br />
<em>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</em><em><br />
SELECT emp_name FROM emp E WHERE dept_no <strong>IN </strong>(SELECT dept_no FROM dept WHERE dept_no = E.dept_no AND dept_Cat = &#8216;A&#8217;);<br />
</em><em>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</em><em><br />
SELECT emp_name FROM dept D, emp E WHERE E.dept_no = D.dept_no AND D.dept_cat = &#8216;A&#8217;;</em></li>
<li>Where possible use EXISTS rather than DISTINCT, to avoid full table scan as DISTINCT operator causes Oracle to fetch all rows satisfying the table join and then sort and filter out duplicate values. EXISTS is a faster alternative, because the Oracle optimizer realizes when the subquery has been satisfied once, there is no need to proceed further and the next matching row can be fetched.<br />
<em>Use:<br />
SELECT S.id, S.description FROM small_table S WHERE <strong>EXISTS </strong>(SELECT NULL FROM big_table B WHERE B.id = S.id);<br />
Rather than:<br />
SELECT <strong>DISTINCT S.id, S.description</strong> FROM small_table S, big_table B<br />
WHERE S.id = B.id;</em></li>
<li>Where possible use a non-column expression (putting the column on one side of the operator and all the other values on the other). Non-column expressions are often processed earlier thereby speeding the query.<br />
<em>Use:<br />
</em><em>WHERE SALES &lt; 1000/(1 + n);</em><em><br />
Rather than:<br />
</em><em>WHERE SALES + (n * SALES) &lt; 1000;</em></li>
<li>Where possible use UNION ALL rather than using UNION. The UNION clause forces all rows retuned by each portion of the UNION to be sorted and merged and duplicates to be filtered out before the first row is returned. A UNION ALL simply returns all rows including duplicates and does not have to perform any sort, merge or filter. If your tables are mutually exclusive(include no duplicate records), or you don&#8217;t care if duplicates are returned, the UNION ALL is much more efficient.<br />
<em>USE:</em><br />
<em>SELECT acct_num, balance_amt FROM debit_transactions WHERE tran_date = &#8217;31-DEC-95&#8242;<br />
<strong>UNION ALL</strong><br />
SELECT acct_num, balance_amt FROM credit_transactions WHERE tran_date = &#8217;31-DE -95&#8242;;<br />
Rather than:<br />
SELECT acct_num, balance_amt FROM debit_transactions WHERE tran_date = &#8217;31-DEC-95&#8242;<br />
<strong>UNION</strong><br />
SELECT acct_num, balance_amt FROM credit_transactions WHERE tran_date = &#8217;31-DE -95&#8242;;</em></li>
<li>Consider using DECODE to avoid having to scan the same rows repetitively or join the same table repetitively. Note, DECODE is not necessarily faster as it depends on your data and the complexity of the resulting query. Also, using DECODE requires you t change your code when new values are allowed in the field.<br />
<em>USE:<br />
SELECT COUNT(<strong>DECODE</strong>(status,&#8217;Y',&#8217;X',NULL)) Y_count,<br />
COUNT(<strong>DECODE</strong>(status,&#8217;N',&#8217;X',NULL)) N_count<br />
FROM emp WHERE emp_name LIKE &#8216;SMITH%&#8217;;<br />
Raher than:<br />
SELECT COUNT(*) FROM emp WHERE status = &#8216;Y&#8217; AND emp_name LIKE &#8216;SMITH%&#8217;;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
SELECT COUNT(*) FROM emp WHERE status = &#8216;N&#8217; AND emp_name LIKE &#8216;SMITH%&#8217;;</em></li>
<li>Oracle automatically performs simple column type conversions(or casting) when it compares columns of different types. Depending on the type of conversion, indexes may not be used. Make sure you declare your program variables as the same type as your Oracle columns, if the type is supported in the programming language you are using.<br />
<em>Use:<br />
SELECT emp_no, emp_name, sal FROM emp WHERE emp_no = &#8217;123&#8242;;<br />
HERE if emp_no indexed numeric, then after implicit conversion query will be:<br />
SELECT emp_no, emp_name, sal FROM emp WHERE emp_no = <strong>TO_NUMBER</strong>(&#8217;123&#8242;); </em><br />
<em>Thus, index is used in this case.<br />
Don&#8217;t use:<br />
SELECT emp_no, emp_name, sal FROM emp WHERE emp_type = 123;<br />
HERE if emp_type is indexed varchar2, then after implicit conversion query will be:</em><br />
<em>SELECT emp_no, emp_name, sal FROM emp WHERE TO_NUMBER(emp_type) = 123;</em><br />
<em>Thus, index will not be used in this case.</em></li>
<li>The most efficient method for storing large binary objects, i.e. multimedia objects, is to place them in the file system and place a pointer in the DB.</li>
<li>B-Tree Indexes do not store entries for NULL, so IS NULL is not indexable, but IS NOT NULL is indexable and thus if a huge table contains very few not null values then you should go for B-Tree indexes. On the other hand bitmap indexes support IS NULL condition.<br />
<em>SELECT * FROM big WHERE status IS NOT NULL; (Use B-tree index in this case)</em></li>
<li>Avoid using functions on indexed columns unless a function-based index is created; as it leads to full table scan even though index exists on the column.</li>
</ul>
<p><strong>Avoid using the following:</strong></p>
<ul type="disc">
<li>Boolean operators &gt;, &lt;, &gt;=, &lt;=, IS NULL, IS NOT NULL</li>
<li>NOT IN, !=</li>
<li>Like &#8216;%pattern&#8217;, not exists</li>
<li>Calculations on unindexed columns or (use union instead)</li>
<li>Having (use a WHERE clause instead when appropriate)</li>
</ul>
<p><strong> </strong><strong>Do use the following:</strong></p>
<ul type="disc">
<li>Enable aliases to prefix all columns</li>
<li>Place indexed columns higher in the WHERE clause</li>
<li>Use SQL Joins instead of using sub-queries</li>
<li>Make the table with the least number of rows, the driving table, by making it first in the FROM clause</li>
</ul>
<p><strong>Other important points for SQL Tuning</strong></p>
<ul type="disc">
<li>Establish a tuning environment that reflects your production database</li>
<li>Establish performance expectations before you begin</li>
<li>Always Design and develop with performance in mind</li>
<li>Create Indexes to support selective WHERE clauses and join conditions</li>
<li>Use concatenated indexes where appropriate</li>
<li>Consider indexing more than you think you should, to avoid table lookups</li>
<li>Pick the best join method</li>
<li>Nested loops joins are best for indexed joins of subsets</li>
<li>Hash joins are usually the best choice for &#8220;big&#8221; joins</li>
<li>Pick the best join order</li>
<li>Pick the best &#8220;driving&#8221; table</li>
<li>Eliminate rows as early as possible in the join order</li>
<li>Use bind variables. Bind variables are key to application scalability</li>
<li>Use Oracle hints where appropriate</li>
<li>Compare performance between alternative syntax for your SQL statement</li>
<li>Consider utilizing PL/SQL to overcome difficult SQL tuning issues</li>
<li>Consider using third party tools to make the job of SQL tuning easier</li>
</ul>
<p>Performing these steps is easy and provides a tremendous benefit and performance boost. Follow these simple steps and you can increase your system performance.</p>
<div class="printfriendly alignleft"><a href="http://www.oratraining.com/blog/2009/06/oracle-sql-tuning-tips/?pfstyle=wp" rel="nofollow" ><img src="//cdn.printfriendly.com/pf-button-both.gif" alt="Print Friendly" /></a></div><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Oracle+SQL+tuning+tips+http%3A%2F%2Foratraining.com%2Fblog%2F%3Fp%3D176" title="Post to Twitter"><img class="nothumb" src="http://www.oratraining.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big3.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.oratraining.com/blog/2009/06/oracle-sql-tuning-tips/&amp;title=Oracle+SQL+tuning+tips" title="Post to Digg"><img class="nothumb" src="http://www.oratraining.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg-big4.png" alt="Post to Digg" /></a></p></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.oratraining.com%2Fblog%2F2009%2F06%2Foracle-sql-tuning-tips%2F&amp;title=Oracle%20SQL%20tuning%20tips" id="wpa2a_2"><img src="http://www.oratraining.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.oratraining.com/blog/2009/06/oracle-sql-tuning-tips/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Oracle Export and Import utility tutorial</title>
		<link>http://www.oratraining.com/blog/2009/06/oracle-export-import-utility-exp-imp-tutorial/</link>
		<comments>http://www.oratraining.com/blog/2009/06/oracle-export-import-utility-exp-imp-tutorial/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 12:57:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database Performance Tuning]]></category>
		<category><![CDATA[Database programming]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[Oracle DBA]]></category>
		<category><![CDATA[Oracle developers]]></category>
		<category><![CDATA[exp]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[imp]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://www.oratraining.com/blog/?p=169</guid>
		<description><![CDATA[Tweet Oracle Data Export and Import utility The Import and Export utilities work together; Export sends database definitions and actual data to an export file and Import can read the file to perform many different tasks. You can use Export and Import for many important database tasks, such as restoring a table, generating CREATE scripts, [...]]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.oratraining.com%2Fblog%2F2009%2F06%2Foracle-export-import-utility-exp-imp-tutorial%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.oratraining.com/blog/2009/06/oracle-export-import-utility-exp-imp-tutorial/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.oratraining.com/blog/2009/06/oracle-export-import-utility-exp-imp-tutorial/"  data-text="Oracle Export and Import utility tutorial" data-count="horizontal">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://www.oratraining.com/blog/2009/06/oracle-export-import-utility-exp-imp-tutorial/" data-counter="right"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><h2>Oracle Data Export and Import utility</h2>
<p>The Import and Export utilities work together; Export sends database definitions and actual data to an export file and Import can read the file to perform many different tasks. You can use Export and Import for many important database tasks, such as restoring a table, generating CREATE scripts, copying data among Oracle databases, migrating among Oracle versions, and moving tables from one schema to another.</p>
<p>Oracle&#8217;s export (exp) and import (imp) utilities are used to perform logical database backup and recovery. When exporting, database objects are dumped to a binary file which can then be imported into another Oracle database.</p>
<p>These utilities can be used to move data between different machines, databases or schema. However, as they use a proprietary binary file format, they can only be used between Oracle databases. One cannot export data and expect to import it into a non-Oracle database.</p>
<p>Various parameters are available to control what objects are exported or imported. To get a list of available parameters, run the <em>exp</em> or <em>imp</em> utilities with the <em>help=yes</em> parameter i.e. &#8220;<em>exp help=yes</em>&#8221; or &#8220;<em>imp help=yes</em>&#8220;.</p>
<p>The export/import utilities are commonly used to perform the following tasks:<span id="more-169"></span></p>
<ul>
<li><strong><em>Back up and recover objects</em></strong><strong>.</strong> Perhaps the most widely used Export and Import feature is the capability to serve as a useful backup solution. Most Oracle installations use full online or hot backups to back up the entire database in the event of a CPU, network, or disk failure. This works well because all data can be restored to the very millisecond that the database crashed. However, Export and Import provide for extra safety. If just one table in the entire database needs to be recovered during a full backup, the entire database would have to be recovered on another machine, and the one table would be copied back over into the original database. This incredibly time- and resource-consuming task could become a real headache in distributed databases. Export and Import can save you this trouble by exporting the entire database and importing just the tables that need to be recovered. Now that point-in-time recovery is an option for <em>tablespaces </em>in Oracle8, Export and Import can also serve as a backup and recovery mechanism for the entire database.</li>
<li><strong><em>Copy objects among schemas</em></strong><strong>.</strong> You can use Export and Import to copy all object types such as tables, indexes, grants, procedures, and views from one schema to another. You can specify which objects you want to move, and provide the FROM and TO schemas. Oracle does the rest automatically.</li>
<li><strong><em>Copy objects among Oracle databases</em></strong><strong>.</strong> You can export a table in one Oracle database and import that table into another. Many businesses export key tables and send the export files to a remote office location, which can then use Import to load the data into its local database. This is a form of one-way data replication to remote locations.</li>
<li><strong><em>Generate </em></strong><strong><em>CREATE</em></strong><strong><em> scripts</em></strong>. Export and Import contain powerful options that allow you to generate CREATE scripts for tables, partitions, indexes, object-type definitions, views, grants, constraints, rollback segments, tablespaces, and all other objects in the database. This safeguards the structure of your objects, in case one gets corrupted or deleted.</li>
<li><strong><em>Migrate databases from one Oracle version to another</em></strong>. You can upgrade (or downgrade) the version of Oracle by using the Export and Import utilities. For example, you can export an Oracle7 database, copy the export file to an Oracle8 database server, and then import into the Oracle8 server. This process, called <em>migration</em>, makes the data and application function in an Oracle8 environment. Of course, we always recommend complete testing before relying on the results of a migration.</li>
<li><strong><em>Defragment a tablespace</em></strong>. Fragmentation occurs when tables and indexes are created, dropped, enlarged, and reduced in size over time. Fragmentation also occurs when an object&#8217;s <em>storage parameters </em>are sized improperly. To defragment a tablespace, you can export a tablespace, coalesce the free space (or drop and recreate the tablespace), and import the objects again.</li>
</ul>
<p>Because of the special binary format, files which had been created by the EXPORT utility can only be read by IMPORT. Both tools are only used to maintain ORACLE database objects.</p>
<p>SQL*Loader is similar to Import in that it can load data; the main difference is that Import can read only Oracle export files. SQL*Loader can read text files generated by non-Oracle databases.To load data from other systems into the database you have to use SQL*LOADER or other programs. To store data from database into readable operating system files you may use e.g. REPORTS, SQLPLUS.</p>
<p>While still supported on 10g the original import (<em>imp</em>) and export (<em>exp</em>) utilities were replaced in 10g with the faster and more advanced Data Pump-based import-export, <em>impdp</em> and <em>expdp</em>.</p>
<p>NOTE: It is generally advised not to use exports as the only means of backing-up a database. Physical backup methods (for example, when you use RMAN) are normally much quicker and supports point in time based recovery (apply archivelogs after recovering a database). Also, exp/imp is not practical for large database environments.</p>
<p>On 11g just imp will be still available, so if you using 10g, now is the time to starting using data pump.</p>
<h2>Prerequisites/Requirements</h2>
<p>exp and imp are utilities present in the <strong><em>$ORACLE_HOME/bin</em></strong> directory and are installed when Oracle is installed. Their prime purpose is to move logical objects out of and into the database respectively &#8211; for example dumping all of the tables owned by a user to a single file is achieved using the exp utility. It is important to distinguish between dumping data in this manner and backing up the database which is normally achieved using the <em>rman</em> utility.</p>
<p><strong><em>$ORACLE_HOME, $ORACLE_SID</em></strong> and <strong><em>$PATH</em></strong> environment variables need to be set appropriately in a unix environment and the <strong><em>%ORACLE_SID%</em></strong> environment variable needs to be set in a windows environment, before executing these commands. If you login as the owner of the oracle software (usually the oracle user on unix) these are likely to have been set in the users profile. The Oracle Database instance needs to be up in order to export/import data. Type <em>&#8216;imp help=y&#8217;</em> or <em>&#8216;exp help=y&#8217;</em> for a detailed explanation of the available options for these utilities.</p>
<p>It is a prerequisite that <strong><em>oraenv</em></strong> or <strong><em>coraenv</em></strong> (if you are working in a c-shell) was executed before you export-import data. Consider, if you stored data in the database by using an national language support (NLS) other than AMERICAN you have to change your environment before import-export.<br />
Example for a german environment:<br />
<strong><em>NLS_LANG=GERMAN_GERMANY.WE8ISO8859P1</em></strong><strong><em><br />
</em></strong><strong><em>export NLS_LANG</em></strong></p>
<p>In order to use exp and imp, the <strong><em>catexp.sql</em></strong> script must be run. <em>catexp.sql</em> basically creates the <strong><em>exp_full_database</em></strong> and <strong><em>imp_full_database</em></strong> roles. It is found under <strong><em>$ORACLE_HOME/rdbms/admin</em></strong>:</p>
<p>SQL&gt; @?/rdbms/admin/catexp</p>
<p><em>catexp</em> is called by <em>catalog.sql</em>. Note: SQL*Plus provides a shortcut to refer to the ORACLE_HOME directory: the question mark (<strong>?</strong>).</p>
<p>One must have the create session privilege for being able to use exp. If objects of another user&#8217;s schema need to be exported, the <strong><em>EXP_FULL_DATABASE</em></strong> role is required.</p>
<p>Before one imports rows into already populated tables, one needs to truncate or drop these tables to get rid of the old data. If not, the new data will be appended to the existing tables or it&#8217;ll get rejected. Either way, use the same syntax when you are ready to import the data. One must always DROP existing Sequences before re-importing. If the sequences are not dropped, they will generate numbers inconsistent with the rest of the database.</p>
<p>Note: It is also advisable to drop indexes before importing to speed up the import process. Indexes can easily be recreated after the data was successfully imported.</p>
<p><strong>Control and Configure Export-Import</strong><strong><br />
</strong>FULL, OWNER, and TABLE are the three types of exports. A FULL export exports all objects, structures, and data within the database for all schemas. OWNER exports only those objects owned by the specified user accounts. TABLE exports only the specified tables and partitions for specific user accounts.</p>
<p>Because dozens of object types can be exported, it&#8217;s important to distinguish what gets exported with each export category:</p>
<ul>
<li>With <strong>TABLE</strong>, the specified table (or cluster or partition) is exported with its indexes, referential integrity constraints, synonyms, and triggers.</li>
<li>With <strong>OWNER</strong> specified, all the specified schema&#8217;s objects are exported. This includes database links, sequences, packages/procedures/functions, object-type definitions, clusters/tables/partitions, postable actions, synonyms, views, triggers, snapshots/snapshot logs, job queues, and refresh groups.</li>
<li>With the <strong>FULL</strong> option, all objects described in OWNER are exported for every user account, in addition to tablespace definitions, profiles, user definitions (and encrypted passwords), roles, resource costs, rollback segment definitions, directory aliases, user history table, and auditing options.</li>
</ul>
<p>You can use the Export and Import utilities in <strong><em>interactive</em></strong> or <strong><em>non-interactive</em></strong> mode. In interactive mode, Oracle steps you through the process, prompting for basic Import/Export session information. This method, however, limits you to the simple prompts that Oracle provides. You have more flexibility in non-interactive mode because you can supply up to 23 parameters for the Export utility and 24 parameters for the Import utility. The parameters may be supplied at the command line or by specifying a command file that contains all parameters and values. You can automate Export and Import sessions by using a command file, or repeat them over and over again manually.</p>
<p>The syntax of running Export and Import is as follows:<br />
<em>EXP KEYWORD=value or keyword=(value1,value2,&#8230;,valueN)<br />
IMP KEYWORD=value or keyword=(value1,value2,&#8230;,valueN)</em><br />
Replace KEYWORD with the parameter, and value with what should be the parameter&#8217;s value. For example, use the following to export the entire database:<br />
<em>EXP USERID=SYSTEM/MANAGER FULL=Y</em></p>
<p>Use the following to import the EMP and DEPT tables owned by the SCOTT user account: <em>IMP USERID=SYSTEM/MANAGER FROMUSER=SCOTT TABLES=(EMP,DEPT)</em>The following examples demonstrate how the imp/exp utilities can be used:<br />
<em>exp scott/tiger file=emp.dmp log=emp.log tables=emp rows=yes indexes=no<br />
exp scott/tiger file=emp.dmp tables=(emp,dept)<br />
imp scott/tiger file=emp.dmp full=yes<br />
imp scott/tiger file=emp.dmp fromuser=scott touser=scott tables=dept</em><em> </em></p>
<p>Using a parameter file:<br />
<em>exp userid=scott/tiger@orcl parfile=export.txt</em><br />
&#8230; where export.txt contains:<br />
BUFFER=100000<br />
FILE=account.dmp<br />
FULL=n<br />
OWNER=scott<br />
GRANTS=y<br />
COMPRESS=y<br />
NOTE: If you do not like command line utilities, you can import and export data with the &#8220;Schema Manager&#8221; GUI that ships with Oracle Enterprise Manager (OEM).<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 />
<em>The EXPORT utility may be used in three ways: </em></p>
<ul>
<li>Interactive dialogue<br />
Simply type <strong>exp</strong>. You will be prompted for your ORACLE userid, password. All other prompts answer by pressing the return key. This is the easiest way to export all data you stored in the ORACLE database. You may assign other values than the defaults to the parameters but in most cases it is unnecessary.</li>
<li>Controlled through bypassed parameters<br />
You may bypass parameters when you export data from the database. Type:<br />
<strong><em>exp</em></strong><em> &lt;userid<strong>/</strong>password&gt; &lt;parameter&gt;<strong>=</strong>&lt;value&gt;,&lt;parameter&gt;<strong>=</strong>&lt;value&gt;,&#8230;</em><br />
Example of exporting scott&#8217;s tables EMP and DEPT to file empdept.expdat and storing all messages to file empdept.log:<br />
<em>exp scott/tiger file=empdept.expdat tables=(EMP,DEPT) log=empdept.log</em></li>
<li>Parameterfile controlled<br />
Instead of typing the parameters on the commandline you may use a parameter file where the parameters are stored. The syntax for this method is: <em>exp &lt;userid/password&gt; parfile=&lt;filename&gt;</em></li>
</ul>
<p>Do not ignore warnings and messages. Look at your logfile and repeat EXPORT until you get messages like:</p>
<pre><em>About to export specified tables ...
. exporting table                            EMP       14 rows exported
. exporting table                           DEPT        4 rows exported
Export terminated successfully without warnings.</em>
--------------------------------------------------------------------------------------
Like Export the <em>Import utility</em> is controlled by parameters. To get familiar with these parameters type: <em>imp help=y</em>
You will get a short description of usage and default settings of parameters.
To start IMPORT simply type <strong>imp</strong>. You will be prompted for your ORACLE userid, password. The next prompts depend on what you answer. In most cases you may answer the prompts by pressing the return key. But the following prompts you have to answer carefully.
<em>Import file: expdat.dmp &gt;
</em>If your data was exported to file expdat.dmp press return, otherwise enter the filename where the exported data resides.
<em>Ignore create error due to object existence (yes/no): yes &gt;
</em>This is a flag to indicate how object creation errors should be handeld. If you import into an existing table and you set <strong><em>IGNORE=Y</em></strong>, rows could be duplicated if they where already present in the table.
<em>Import entire export file (yes/no): yes &gt; no
Username:
</em>If your exportfile consists of more objects than you want to import, enter no. In this case you will be prompted for the Username (this is normally your ORACLE account). <em>Enter table names. Null list means all tables for user
Enter table name or . if done:
</em>After entering the username you will be prompted for table names until you press the return key without entering a table name. Than IMPORT will be started.

Instead of the dialogue method you may use parameters. This is analogous to the methods described for EXPORT.
Examples:
<em>imp &lt;userid/password&gt; tables=(table1,table2)</em><em>
</em>Tables table1, table2 will be imported from the default file export.dmp into the database.
<em>imp &lt;userid/password&gt; parfile=&lt;filename&gt;</em>
Import will be controlled by the named parameterfile.
After importing you should get messages like:</pre>
<pre><em>importing SCOTT's objects into SCOTT
. importing table "DEPT"                                     4 rows imported
. importing table "EMP"                                     14 rows imported
Import terminated successfully without warnings.</em>
-----------------------------------------------------------------------------------</pre>
<p><strong>Parameters for the Export utility</strong></p>
<p>Table below lists all parameters that can be used with the Export utility, along with their default values (if any).</p>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td width="144" valign="top"><strong>Parameter</strong></td>
<td width="96" valign="top"><strong>Default Value</strong></td>
<td width="336" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td width="144" valign="top">BUFFER</td>
<td width="96" valign="top">OS-dependent</td>
<td width="336" valign="top">The size of BUFFER (in bytes) determines the memory buffer through which rows are exported. This should be larger than the size of the largest record multiplied by the number of rows that you want to fit within the buffer.</td>
</tr>
<tr>
<td width="144" valign="top">COMPRESS</td>
<td width="96" valign="top">Y</td>
<td width="336" valign="top">If COMPRESS=Y, the INITIAL storage parameter is set to the total size of all extents allocated for the object. The change takes effect only when the object is imported.</td>
</tr>
<tr>
<td width="144" valign="top">CONSISTENT</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">Setting CONSISTENT=Y exports all tables and references in a consistent state. This slows the export, as rollback space is used. If CONSISTENT=N and a record is modified during the export, the data will become inconsistent.</td>
</tr>
<tr>
<td width="144" valign="top">CONSTRAINTS</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">Specifies whether table constraints are exported.</td>
</tr>
<tr>
<td width="144" valign="top">DIRECT</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">If DIRECT=Y, Oracle bypasses the SQL command-processing layer, improving the speed of the export. Unfortunately, the new object types endemic to Oracle8, such as LOBs, don&#8217;t get exported.</td>
</tr>
<tr>
<td width="144" valign="top">FEEDBACK</td>
<td width="96" valign="top">0</td>
<td width="336" valign="top">Oracle displays a period for each group of records inserted. FEEDBACK defines the size of the group. For example, if FEEDBACK=1000, a period will be displayed for every 1,000 records imported. This parameter is useful for tracking the progress of large imports.</td>
</tr>
<tr>
<td width="144" valign="top">FILE</td>
<td width="96" valign="top">expdat.dmp</td>
<td width="336" valign="top">By default, expdat.dmp (stands for EXPort DATa.DuMP) is the filename. For a more meaningful name, change the FILE parameter.</td>
</tr>
<tr>
<td width="144" valign="top">FULL</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">The entire database will be exported if FULL=Y, including tablespace definitions.</td>
</tr>
<tr>
<td width="144" valign="top">GRANTS</td>
<td width="96" valign="top">Y</td>
<td width="336" valign="top">Specifies whether all grant definitions are exported for the objects being exported.</td>
</tr>
<tr>
<td width="144" valign="top">HELP</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">No other parameters are needed if you specify HELP=Y. A basic help screen will appear.</td>
</tr>
<tr>
<td width="144" valign="top">INCTYPE</td>
<td width="96" valign="top"></td>
<td width="336" valign="top">The valid options for this parameter are COMPLETE, CUMULATIVE, and INCREMENTAL. A COMPLETE export lays down a full export for which the other two options rely on for restores of the database. CUMULATIVE exports all tables and other objects that have changed since the last CUMULATIVE or COMPLETE export was taken; if one record in a table is altered, the entire table is exported. INCREMENTAL exports all tables and objects that have changed since the last INCREMENTAL, CUMULATIVE, or COMPLETE export.</td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td width="600" valign="top"><strong>How can you easily see the Export/Import parameters and syntax?</strong></td>
</tr>
<tr>
<td width="600" valign="top">If you don&#8217;t have this book handy when necessary and haven&#8217;t memorized the dozens of parameters, the Export and Import utilities have a handy reference built in. Typing EXP HELP=Y or IMP HELP=Y at a command prompt brings up a nice one-page reference manual.</td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td width="185" valign="top"><strong>Parameter</strong></td>
<td width="88" valign="top"><strong>Default Value</strong></td>
<td width="303" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td width="185" valign="top">INDEXES</td>
<td width="88" valign="top">Y</td>
<td width="303" valign="top">Specifies whether user-defined indexes are exported. System indexes created with constraints (primary key, unique key) and OID indexes are automatically exported, regardless of this parameter&#8217;s value.</td>
</tr>
<tr>
<td width="185" valign="top">LOG</td>
<td width="88" valign="top"></td>
<td width="303" valign="top">Specifies the name of the file to spool the feedback from the export session. Unless otherwise specified, Oracle appends a .LOG extension to the file.</td>
</tr>
<tr>
<td width="185" valign="top">PARFILE</td>
<td width="88" valign="top"></td>
<td width="303" valign="top">Rather than enter all parameters on the command line, some or all can be kept in a parameter file. This parameter specifies which file to use, if desired. This parameter is especially useful for non-interactive import sessions.</td>
</tr>
<tr>
<td width="185" valign="top">POINT_IN_TIME_RECOVER</td>
<td width="88" valign="top">N</td>
<td width="303" valign="top">Exports information for a point-in-time recovery for the tablespace listed with the TABLESPACES parameter.</td>
</tr>
<tr>
<td width="185" valign="top">RECORD</td>
<td width="88" valign="top">Y</td>
<td width="303" valign="top">If you use the INCTYPE parameter with RECORD=Y, the SYS data dictionary tables INCEXP, INCFIL, and INCVID are populated with export data such as owner, type of export, and the time of export.</td>
</tr>
<tr>
<td width="185" valign="top">RECORDLENGTH</td>
<td width="88" valign="top">OS-dependent</td>
<td width="303" valign="top">The RECORDLENGTH parameter is used only when you&#8217;ll import on a machine with a different byte count of the file than on the machine where the export occurs. The default should be used in most import sessions.</td>
</tr>
<tr>
<td width="185" valign="top">RECOVERY_TABLESPACES</td>
<td width="88" valign="top"></td>
<td width="303" valign="top">Used with POINT_IN_TIME_RECOVER;specifies which tablespaces can be recovered by using point-in-time recovery. This is important because imports otherwise can&#8217;t recover transactions past the time of export.</td>
</tr>
<tr>
<td width="185" valign="top">ROWS</td>
<td width="88" valign="top">Y</td>
<td width="303" valign="top">Specifies whether table and object data will be exported. If ROWS=N, only object definitions are exported.</td>
</tr>
<tr>
<td width="185" valign="top">STATISTICS</td>
<td width="88" valign="top">ESTIMATE</td>
<td width="303" valign="top">Specifies whether table and index statistics are to be analyzed with COMPUTE or ESTIMATE when imported. Only those objects that already have statistics on them will be analyzed during import. Specify NONE if no objects should be analyzed.</td>
</tr>
<tr>
<td width="185" valign="top">TABLES</td>
<td width="88" valign="top"></td>
<td width="303" valign="top">Specifies a comma-separated list of all tables to be exported. This parameter could be used with the OWNER parameter to specify which owner to associate the tables with. Tables can also be specified with the owner.table_name format. In a non-UNIX environment such as Windows NT, you must enclose the table list within parentheses.</td>
</tr>
<tr>
<td width="185" valign="top">TABLESPACES</td>
<td width="88" valign="top"></td>
<td width="303" valign="top">List of tablespaces to be exported with the POINT_IN_TIME_RECOVER parameter.</td>
</tr>
<tr>
<td width="185" valign="top">USERID</td>
<td width="88" valign="top"></td>
<td width="303" valign="top">Specifies the username and password for the user conducting the import. The format for the command is username/password. You can also use Net8&#8242;s @connect_string format if you want.</td>
</tr>
</tbody>
</table>
<p><strong>Parameters for the Import utility</strong><strong><br />
</strong>You can use 24 parameters during an import session. They may be specified in the command line or any specified parameter file. Table below lists all the import parameters.</p>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td width="144" valign="top"><strong>Parameter</strong></td>
<td width="96" valign="top"><strong>Default Value</strong></td>
<td width="336" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td width="144" valign="top">ANALYZE</td>
<td width="96" valign="top">Y</td>
<td width="336" valign="top">Imported tables have their statistics analyzed if ANALYZE is set to Y. Only those tables that already had statistics on them during the export are computed. The tables will be ESTIMATED by default, unless the export was performed with the STATISTICS=COMPUTE parameter configuration.</td>
</tr>
<tr>
<td width="144" valign="top">BUFFER</td>
<td width="96" valign="top">OS-dependent</td>
<td width="336" valign="top">The BUFFER size (in bytes) determines the memory buffer through which rows are imported. This should be larger than the size of the largest record multiplied by the number of rows that you want to fit within the buffer.</td>
</tr>
<tr>
<td width="144" valign="top">CHARSET</td>
<td width="96" valign="top"></td>
<td width="336" valign="top">An obsolete Oracle6 parameter, indicating whether the export was done in ASCII or EBCDIC. This information is processed automatically in Oracle7 and Oracle8.</td>
</tr>
<tr>
<td width="144" valign="top">COMMIT</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">By default, a COMMIT occurs after each table, nested table, and partition. If you&#8217;re importing a large table, the rollback segments may grow large. To improve performance while loading large tables, you should set COMMIT=Y.</td>
</tr>
<tr>
<td width="144" valign="top">DESTROY</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">If you set DESTROY=Y and do a full import, Oracle will overwrite any data files that exist. If you use raw devices for your data files, they will be overwritten during a full import, as DESTROY=N won&#8217;t prevent the overwriting of datafiles! Don&#8217;t use this option unless you know what you&#8217;re doing.</td>
</tr>
<tr>
<td width="144" valign="top">FEEDBACK</td>
<td width="96" valign="top">0</td>
<td width="336" valign="top">Oracle displays a period for each group of records inserted. FEEDBACK defines the size of the group. For example, if FEEDBACK=1000, a period is displayed for every 1,000 records imported. This parameter is useful for tracking the progress of large imports.</td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td width="600" valign="top"><strong>Export/Import and non-Oracle databases</strong></td>
</tr>
<tr>
<td width="600" valign="top">The export file (expdat.dmp by default) is a binary file that only Oracle databases can read. Many databases and PC software can export data into delimited text files, but the Export utility can&#8217;t. To transfer data from Oracle to a non-Oracle database, you must make a delimited file manually by spooling from within PL/SQL or SQL*Plus and running a custom-made script.</td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td width="144" valign="top"><strong>Parameter</strong></td>
<td width="96" valign="top"><strong>Default Value</strong></td>
<td width="336" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td width="144" valign="top">FILE</td>
<td width="96" valign="top">expdat.dmp</td>
<td width="336" valign="top">By default, expdat.dmp (stands for EXPort DATa.DuMP) is the name of the file that Import will import from. If the file is something other than expdat.dmp, specify it with this parameter.</td>
</tr>
<tr>
<td width="144" valign="top">FROMUSER</td>
<td width="96" valign="top"></td>
<td width="336" valign="top">Specifying this parameter imports only those objects owned by the FROMUSER user account.</td>
</tr>
<tr>
<td width="144" valign="top">FULL</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">The entire database will be imported if FULL=Y.</td>
</tr>
<tr>
<td width="144" valign="top">GRANTS</td>
<td width="96" valign="top">Y</td>
<td width="336" valign="top">Specifies whether all grants will be created for the exported objects.</td>
</tr>
<tr>
<td width="144" valign="top">HELP</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">No other parameters are needed if you specify HELP=Y. A basic help screen will appear.</td>
</tr>
<tr>
<td width="144" valign="top">IGNORE</td>
<td width="96" valign="top">N</td>
<td width="336" valign="top">If IGNORE=Y, object creation errors are ignored, and records are inserted into the table. Duplicate records can result, if no unique constraints exist for the table. Non-object creation errors are still reported, such as operating system problems.</td>
</tr>
<tr>
<td width="144" valign="top">INCTYPE</td>
<td width="96" valign="top"></td>
<td width="336" valign="top">If you&#8217;re importing an incremental export, tables are dropped and recreated. You must first restore from the last SYSTEM export (specify INCTYPE=SYSTEM). Then import every incremental export (specify INCTYPE=RESTORE) until the desired changes are applied to the database.</td>
</tr>
<tr>
<td width="144" valign="top">INDEXES</td>
<td width="96" valign="top">Y</td>
<td width="336" valign="top">Specifies whether user-defined indexes are imported. System indexes created with constraints (primary key, unique key) and OID indexes are automatically imported, regardless of this parameter&#8217;s value.</td>
</tr>
<tr>
<td width="144" valign="top">INDEXFILE</td>
<td width="96" valign="top"></td>
<td width="336" valign="top">Specifies the name of the file to generate CREATE INDEX statements. Unless otherwise specified, Oracle appends an .SQL extension to the file. (This parameter is explained in more detail later in this chapter.)</td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td width="600" valign="top"><strong>Using the </strong><strong>LOG </strong><strong>parameter</strong></td>
</tr>
<tr>
<td width="600" valign="top">You can specify a <em>log file </em>for the Export and Import sessions with the LOG parameter. The file, which mimics what&#8217;s output to the screen, reports all successful and unsuccessful messages to be examined at a later point. Some Oracle experts use this file during an automated load process and then checks the file for errors. A database administrator is paged if any appear.</td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td width="187" valign="top"><strong>Parameter</strong></td>
<td width="92" valign="top"><strong>Default Value</strong></td>
<td width="298" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td width="187" valign="top">LOG</td>
<td width="92" valign="top"></td>
<td width="298" valign="top">Specifies the name of the file to spool the feedback from the import session. Unless otherwise specified, Oracle appends an .LOG extension to the file.</td>
</tr>
<tr>
<td width="187" valign="top">PARFILE</td>
<td width="92" valign="top"></td>
<td width="298" valign="top">Rather than enter all parameters on the command line, some or all may be kept in a parameter file. The PARFILE parameter specifies which file to use, if desired. This parameter is especially useful for non-interactive import sessions.</td>
</tr>
<tr>
<td width="187" valign="top">POINT_IN_TIME_RECOVER</td>
<td width="92" valign="top">N</td>
<td width="298" valign="top">Performs a point-in-time recovery for the tablespace exported with the TABLESPACES parameter.</td>
</tr>
<tr>
<td width="187" valign="top">RECORDLENGTH</td>
<td width="92" valign="top">OS-dependent</td>
<td width="298" valign="top">Used only when importing on a machine with a different byte count of the file than on the machine where the export occurred. The default should be used in most Import sessions.</td>
</tr>
<tr>
<td width="187" valign="top">SHOW</td>
<td width="92" valign="top">N</td>
<td width="298" valign="top">Displays each SQL statement and doesn&#8217;t apply them to the database. The SQL statements can be viewed and modified when used with the FILE parameter. (The SHOW parameter is explained in more detail later in this chapter.)</td>
</tr>
<tr>
<td width="187" valign="top">SKIP_UNUSABLE_INDEXES</td>
<td width="92" valign="top">N</td>
<td width="298" valign="top">Allows the postponement of index creation until the record data is imported. The indexes affected are only those set to an unusable state, and all other indexes are created if INDEXES=Y (the default value) is set.</td>
</tr>
<tr>
<td width="187" valign="top">TABLES</td>
<td width="92" valign="top"></td>
<td width="298" valign="top">Specifies a comma-separated list of all tables to be imported. You should use this parameter with the FROMUSER parameter. In a non-UNIX environment, such as Windows NT, enclose the table list within parentheses.</td>
</tr>
<tr>
<td width="187" valign="top">TOUSER</td>
<td width="92" valign="top"></td>
<td width="298" valign="top">Specifies the user account into which tables should be imported, if you want it to be different from the original owner of the tables. This parameter needs to be used with the FROMUSER parameter.</td>
</tr>
<tr>
<td width="187" valign="top">USERID</td>
<td width="92" valign="top"></td>
<td width="298" valign="top">Specifies the username and password for the user conducting the import. The format for the command is username/password. You may also use Net8&#8242;s @connect_string format if desired.</td>
</tr>
</tbody>
</table>
<h2>&#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;&#8211;Using imp/exp across different Oracle version</h2>
<p>If exp and imp are used to export data from an Oracle database with a different version than the database in which is imported, then the following rules apply:</p>
<ul>
<li>1. exp must be of the lower version</li>
<li>2. imp must match the target version</li>
</ul>
<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;&#8212;&#8212;&#8212;&#8212;&#8211;<strong>Common Export/Import Errors</strong></p>
<ul>
<li><strong>ORA-00001: Unique constraint (&#8230;) violated</strong><br />
You are importing duplicate rows. Use IGNORE=YES to skip tables that already exist (imp will give an error if the object is re-created) OR Perform the following actions:</li>
<li>1. Back up the target table.</li>
<li>2. Try deleting the target table.</li>
<li>3. Run the import for this table again in overwrite mode.</li>
<li><strong>ORA-01555: Snapshot too old</strong><br />
Ask your users to STOP working while you are exporting or try using parameter CONSISTENT=NO</li>
<li><strong>ORA-01562: Failed to extend rollback segment</strong><br />
Create bigger rollback segments or set parameter COMMIT=Y while importing</li>
<li><strong>IMP-00015: Statement failed &#8230; object already exists&#8230;</strong><br />
Use the IGNORE=Y import parameter to ignore these errors, but be careful as you might end up with duplicate rows.</li>
</ul>
<p><a name="BACDAACC"></a><a name="i1008356"></a><a name="BACFJHAI"></a><a name="i1008361"></a><a name="BACGIDJI"></a><a name="i1008366"></a><a name="BACHBHDD"></a><a name="i1008371"></a><a name="BACHJCCC"></a>&#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;&#8212;&#8211;<br />
<strong>To Improve performance<em> </em></strong></p>
<p><strong>Export</strong></p>
<ul>
<li>Set the BUFFER parameter to a high value (e.g. 2Mb &#8212; entered as an integer &#8220;2000000&#8243;)</li>
<li>Set the RECORDLENGTH parameter to a high value (e.g. 64Kb &#8212; entered as an integer &#8220;64000&#8243;)</li>
<li>Use DIRECT=yes (direct mode export)</li>
<li>Stop unnecessary applications to free-up resources for your job.</li>
<li>If you run multiple export sessions, ensure they write to different physical disks.</li>
<li>DO NOT export to an NFS mounted filesystem. It will take forever.</li>
</ul>
<p><strong>Import</strong><strong><em> </em></strong></p>
<ul>
<li>Create an indexfile so that you can create indexes AFTER you have imported data. Do this by setting INDEXFILE to a filename and then import. No data will be imported but a file containing index definitions will be created. You must edit this file afterwards and supply the passwords for the schemas on all CONNECT statements. <strong><em> </em></strong></li>
<li>Place the file to be imported on a separate physical disk from the oracle data files<strong><em> </em></strong></li>
<li>Increase DB_CACHE_SIZE (DB_BLOCK_BUFFERS prior to 9i) considerably in the init$SID.ora file <strong><em> </em></strong></li>
<li>Set the LOG_BUFFER to a big value and restart oracle. <strong><em> </em></strong></li>
<li>Stop redo log archiving if it is running (ALTER DATABASE NOARCHIVELOG;)<strong><em> </em></strong></li>
<li>Create a BIG tablespace with a BIG rollback segment inside. Set all other rollback segments offline (except the SYSTEM rollback segment of course). The rollback segment must be as big as your biggest table (I think?) <strong><em> </em></strong></li>
<li>Use COMMIT=N in the import parameter file if you can afford it <strong><em> </em></strong></li>
<li>Use STATISTICS=NONE in the import parameter file to avoid time consuming to import the statistics <strong><em> </em></strong></li>
<li>Remember to run the indexfile previously created <strong><em> </em></strong></li>
</ul>
<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;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
<strong>Good practices</strong></p>
<ul>
<li>Always take care about CHARSETS when you do export and import. Using the wrong ones can convert your data in a lossy manner. The best situation is when your source and destination database have the same character sets, so you can avoid completely any character conversion. You control this behavior by setting NLS_LANG environment variable appropriately. When not set properly you may see &#8216;Exporting questionable statistics&#8217; messages.</li>
<li>After doing an export, it is better to check your dump by doing an import with the parameter SHOW=Y. This checks the validity of your dump file.</li>
</ul>
<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;&#8212;&#8212;&#8212;&#8212;<strong>Other considerations</strong></p>
<ul>
<li>You may need to patch your Oracle client (where you are running exp/imp) to the same level as the Oracle server to prevent errors</li>
<li>When importing large amounts of data consider dropping indexes prior to the import to speed up the process and re-creating them once the import is completed</li>
<li>The amount of archive logs that may be created on a large import may fill up your disk</li>
<li>On INSERT triggers will fire, consider whether these need to be disabled</li>
<li>Increasing the RECORDLENGTH (max 65535) parameter can improve the length of time to perform an import/export as well as DIRECT=y for export</li>
</ul>
<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 />
Tablespace fragmentation occurs when objects are created, dropped, enlarged, and shrunk. The more often this occurs, the more fragmented the tablespace becomes. This causes free space to be broken into many separated island-like chunks of space. In addition, if an object has multiple extents, they could be spread out over different parts of the tablespace; this causes performance and maintenance problems. With many small blocks of free space instead of fewer large free spaces, you may be unable to create some objects that you otherwise could have. By defragmenting the tablespace, the data is reorganized so that all free space is put into one contiguous area, and each object&#8217;s extents are grouped next to each other.</p>
<ul>
<li>The Export and Import utilities can fix fragmentation in two ways:<br />
They can take a table with multiple extents and resize it into a table with one larger extent. This larger single extent will encompass the total size of all previous table extents.</li>
<li>They can make all objects within the tablespace adjacent to each other with no island-like characteristics, while at the same time merging all the free space into one larger free space.</li>
</ul>
<p>The easiest and most dramatic method fixes both fragmentation problems for the entire database. The database is shut down during the process. This forces all sessions against the database to stop (which is why it&#8217;s the most dramatic method).</p>
<p>Fixing a table&#8217;s storage parameter is fairly easy compared to the entire tablespace, as only one table is affected. To fix an entire tablespace, you&#8217;ll have to drop and recreate it, along with all the tables within it.</p>
<p><strong>Fix both fragmentation problems quickly</strong></p>
<ul type="disc">
<li>Export the entire database, specifying <tt>FULL=Y</tt> and <tt>COMPRESS=Y</tt>. <tt>FULL=Y</tt> exports the entire database; <tt>COMPRESS=Y</tt> changes the <tt>INITIAL</tt> storage parameter of each table in the database (if necessary) to fit within one extent each. For example, if a table has five 10M extents, the <tt>COMPRESS=Y</tt> specification changes the table to one 50M extent when imported.</li>
<li>Drop and recreate the entire database.</li>
<li>Import the entire database with the <tt>FULL=Y</tt> parameter.</li>
</ul>
<p><strong>Defragment just one tablespace (a less dramatic method)</strong></p>
<ul type="disc">
<li>Determine which tables exist in the tablespace and export just those tables.</li>
<li>Drop all the tables in the tablespace.</li>
<li>Issue the <tt>ALTER TABLESPACE COALESCE</tt> command (or drop and recreate the tablespace). This will coalesce all the free space within the tablespace into one contiguous area.</li>
<li>Import the tables. Oracle will create the tables adjacent to each other within the tablespace, and all free space will still be contiguous in one chunk of space. <strong> </strong></li>
</ul>
<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;-</p>
<p><strong>Some more examples</strong></p>
<p><strong>EXP</strong><br />
To dump a single schema to disk (we use the scott example schema here)</p>
<p>- Login to server which has an Oracle client</p>
<p><em>exp &lt;user&gt;/&lt;password&gt; FILE=scott.dmp OWNER=scott</em><br />
To export specific tables to disk: Login to server which has an Oracle client</p>
<p><em>exp SYSTEM/password FIlE=expdat.dmp TABLES=(scott.emp,hr.countries) </em></p>
<p>The above command uses two users : scott and hr</p>
<p><em> </em></p>
<p><em>exp &lt;user&gt;/&lt;password&gt; FILE=scott.dmp TABLES=(emp,dept) </em></p>
<p>the above is only for one user : scott</p>
<p><strong>IMP<br />
</strong>To import the full database exported in the example above.<br />
<em>imp SYSTEM/password FULL=y FIlE=dba.dmp </em></p>
<p>To import just the dept and emp tables from the scott schema<br />
<em>imp SYSTEM/password FIlE=dba.dmp FROMUSER=scott TABLES=(dept,emp) </em></p>
<p>To import tables and change the owner</p>
<p><em>imp SYSTEM/password FROMUSER=blake TOUSER=scott FILE=blake.dmp TABLES=(unit,manager)</em><br />
To import just the scott schema exported in the example above:<br />
<em>imp &lt;user&gt;/&lt;password&gt; FIlE=scott.dmp</em></p>
<p>If you do not supply any parameters then you enter an interactive session as illustrated below. (Responses to prompts are shown in blue<strong>. </strong>from the prompt type imp and press enter</p>
<p>$&gt;imp<br />
Import: Release 9.2.0.6.0 &#8211; Production on Thu Mar 29 15:07:43 2007<br />
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.<br />
Username: SYSTEM<br />
Password: password<br />
Connected to: Oracle9i Enterprise Edition Release 9.2.0.6.0 &#8211; Production<br />
With the Partitioning, OLAP and Oracle Data Mining options<br />
JServer Release 9.2.0.6.0 &#8211; Production<br />
Import file: expdat.dmp &gt; /mention/path/of/dumpFile/includingFileName.dmp<br />
Enter insert buffer size (minimum is 8192) 30720&gt;<strong> </strong>(press enter to accept default)<br />
Export file created by EXPORT:V09.02.00 via conventional path<br />
import done in US7ASCII character set and AL16UTF16 NCHAR character set<br />
import server uses AL32UTF8 character set (possible charset conversion)<br />
List contents of import file only (yes/no): no &gt; press enter<br />
Ignore create error due to object existence (yes/no): no &gt; press enter<br />
Import grants (yes/no): yes &gt; press enter<br />
Import table data (yes/no): yes &gt; press enter<br />
Import entire export file (yes/no): no &gt; press enter or type no<br />
Username: give the userName for which you want the data to be imported<br />
Enter table(T) or partition(T:P) names. Null list means all tables for user<br />
Enter table(T) or partition(T:P) name or . if done: press enter<br />
. importing TST_001_V2&#8242;s objects into TST_001_V2</p>
<div class="printfriendly alignleft"><a href="http://www.oratraining.com/blog/2009/06/oracle-export-import-utility-exp-imp-tutorial/?pfstyle=wp" rel="nofollow" ><img src="//cdn.printfriendly.com/pf-button-both.gif" alt="Print Friendly" /></a></div><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Oracle+Export+and+Import+utility+tutorial+http%3A%2F%2Foratraining.com%2Fblog%2F%3Fp%3D169" title="Post to Twitter"><img class="nothumb" src="http://www.oratraining.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big3.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.oratraining.com/blog/2009/06/oracle-export-import-utility-exp-imp-tutorial/&amp;title=Oracle+Export+and+Import+utility+tutorial" title="Post to Digg"><img class="nothumb" src="http://www.oratraining.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg-big4.png" alt="Post to Digg" /></a></p></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.oratraining.com%2Fblog%2F2009%2F06%2Foracle-export-import-utility-exp-imp-tutorial%2F&amp;title=Oracle%20Export%20and%20Import%20utility%20tutorial" id="wpa2a_4"><img src="http://www.oratraining.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.oratraining.com/blog/2009/06/oracle-export-import-utility-exp-imp-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle SQL hints</title>
		<link>http://www.oratraining.com/blog/2009/04/oracle-sql-hints/</link>
		<comments>http://www.oratraining.com/blog/2009/04/oracle-sql-hints/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 06:56:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Applications Performance Tuning]]></category>
		<category><![CDATA[Database Performance Tuning]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle DBA]]></category>
		<category><![CDATA[Concurrent manager]]></category>
		<category><![CDATA[oracle applications]]></category>
		<category><![CDATA[Oracle Applications DBA]]></category>

		<guid isPermaLink="false">http://www.oratraining.com/blog/?p=89</guid>
		<description><![CDATA[Tweet /*+ hint */ /*+ hint(argument) */ /*+ hint(argument-1 argument-2) */ All hints except /*+ rule */ cause the CBO to be used. Therefore, it is good practise to analyze the underlying tables if hints are used (or the query is fully hinted. There should be no schema names in hints. Hints must use aliases [...]]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.oratraining.com%2Fblog%2F2009%2F04%2Foracle-sql-hints%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.oratraining.com/blog/2009/04/oracle-sql-hints/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.oratraining.com/blog/2009/04/oracle-sql-hints/"  data-text="Oracle SQL hints" data-count="horizontal">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://www.oratraining.com/blog/2009/04/oracle-sql-hints/" data-counter="right"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>/*+ hint */</p>
<p>/*+ hint(argument) */</p>
<p>/*+ hint(argument-1 argument-2) */</p>
<p>All hints except /*+ rule */ cause the CBO to be used. Therefore, it is good practise to analyze the underlying tables if hints are used (or the query is <em>fully</em> hinted.</p>
<p>There should be no schema names in hints. Hints must use aliases if alias names are used for table names. So the following is wrong:</p>
<p>select /*+ index(scott.emp ix_emp) */ from scott.emp <strong>emp_alias</strong></p>
<p>better:</p>
<p>select /*+ index(<strong>emp_alias</strong> ix_emp) */ &#8230; from scott.emp <strong>emp_alias</strong></p>
<p><strong>Why using hints</strong></p>
<p><span id="more-89"></span><br />
It is a perfect valid question to ask why hints should be used. Oracle comes with an <span style="text-decoration: underline;">optimizer</span> that promises to optimize a <span style="text-decoration: underline;">query&#8217;s execution plan</span>. When this optimizer is really doing a good job, no hints should be required at all.</p>
<p>Sometimes, however, the characteristics of the data in the database are changing rapidly, so that the optimizer (or more accuratly, its statistics) are out of date. In this case, a hint could help.</p>
<p>It must also be noted, that Oracle allows to <em>lock</em> the statistics when they look ideal which should make the hints meaningless again.</p>
<p><strong>Hint categories</strong></p>
<p>Hints can be categorized as follows:</p>
<ul class="unIndentedList">
<li> Hints for Optimization Approaches and Goals,</li>
<li> Hints for Access Paths, Hints for Query Transformations,</li>
<li> Hints for Join Orders,</li>
<li> Hints for Join Operations,</li>
<li> Hints for Parallel Execution,</li>
<li> Additional Hints</li>
</ul>
<p><strong>Documented Hints</strong></p>
<p><strong>Hints for Optimization Approaches and Goals</strong></p>
<ul class="unIndentedList">
<li> ALL_ROWS<br />
One of the hints that &#8216;invokes&#8217; the <span style="text-decoration: underline;">Cost based optimizer</span><br />
ALL_ROWS is usually used for <em>batch processing</em> or <em>data warehousing</em> systems.</li>
<li> FIRST_ROWS<br />
One of the hints that &#8216;invokes&#8217; the <span style="text-decoration: underline;">Cost based optimizer</span><br />
FIRST_ROWS is usually used for <em>OLTP</em> systems.</li>
<li> CHOOSE<br />
One of the hints that &#8216;invokes&#8217; the <span style="text-decoration: underline;">Cost based optimizer</span><br />
This hint lets the server choose (between ALL_ROWS and FIRST_ROWS, based on <span style="text-decoration: underline;">statistics gathered</span>.</li>
<li> RULE<br />
The RULE hint should be considered deprecated as it is dropped from Oracle9i2.</li>
</ul>
<p>See also the following initialization parameters: <span style="text-decoration: underline;">optimizer_mode</span>, <span style="text-decoration: underline;">optimizer_max_permutations</span>, <span style="text-decoration: underline;">optimizer_index_cost_adj</span>, <span style="text-decoration: underline;">optimizer_index_caching</span> and</p>
<p><strong>Hints for Access Paths</strong></p>
<ul class="unIndentedList">
<li> CLUSTER<br />
Performs a <span style="text-decoration: underline;">nested loop</span> by the cluster index of one of the tables.</li>
<li> FULL<br />
Performs <span style="text-decoration: underline;">full table scan</span>.</li>
<li> HASH<br />
Hashes one table (full scan) and creates a hash index for that table. Then hashes other table and uses hash index to find corresponding records. Therefore not suitable for &lt; or &gt; join conditions.</li>
<li> ROWID<br />
Retrieves the row by <span style="text-decoration: underline;">rowid</span></li>
<li> INDEX<br />
Specifying that index index_name should be used on table tab_name: /*+ index (tab_name index_name) */<br />
Specifying that the index should be used the the <span style="text-decoration: underline;">CBO</span> thinks is most suitable. (Not always a good choice).<br />
Starting with Oracle 10g, the index hint can be described: /*+ index(my_tab my_tab(col_1, col_2)) */. Using the index on my_tab that starts with the columns col_1 and col_2.</li>
<li> INDEX_ASC</li>
<li> INDEX_COMBINE</li>
<li> INDEX_DESC</li>
<li> INDEX_FFS</li>
<li> INDEX_JOIN</li>
<li> NO_INDEX</li>
<li> AND_EQUAL<br />
The AND_EQUAL hint explicitly chooses an execution plan that uses an access path that merges the scans on several single-column indexes</li>
</ul>
<p><strong>Hints for Query Transformations</strong></p>
<ul class="unIndentedList">
<li> FACT<br />
The FACT hint is used in the context of the star transformation to indicate to the transformation that the hinted table should be considered as a fact table.</li>
<li> MERGE</li>
<li> NO_EXPAND</li>
<li> NO_EXPAND_GSET_TO_UNION</li>
<li> NO_FACT</li>
<li> NO_MERGE</li>
<li> NOREWRITE</li>
<li> REWRITE</li>
<li> STAR_TRANSFORMATION</li>
<li> USE_CONCAT</li>
</ul>
<p><strong>Hints for Join Operations</strong></p>
<ul class="unIndentedList">
<li> DRIVING_SITE</li>
<li> HASH_AJ</li>
<li> HASH_SJ</li>
<li> LEADING</li>
<li> MERGE_AJ</li>
<li> MERGE_SJ</li>
<li> NL_AJ</li>
<li> NL_SJ</li>
<li> USE_HASH</li>
<li> USE_MERGE</li>
<li> USE_NL</li>
</ul>
<p><strong>Hints for Parallel Execution</strong></p>
<ul class="unIndentedList">
<li> NOPARALLEL</li>
<li> PARALLEL</li>
<li> NOPARALLEL_INDEX</li>
<li> PARALLEL_INDEX</li>
<li> PQ_DISTRIBUTE</li>
</ul>
<p><strong>Additional Hints</strong></p>
<ul class="unIndentedList">
<li> ANTIJOIN <a name="append"></a></li>
<li> APPEND<br />
If a table or an index is specified with <span style="text-decoration: underline;">nologging</span>, this hint applied with an insert statement produces a <strong>direct path insert</strong> which reduces generation of <span style="text-decoration: underline;">redo</span>.</li>
<li> BITMAP</li>
<li> BUFFER</li>
<li> CACHE</li>
<li> CARDINALITY</li>
<li> CPU_COSTING</li>
<li> <span style="text-decoration: underline;">DYNAMIC_SAMPLING</span></li>
<li> INLINE</li>
<li> MATERIALIZE</li>
<li> NO_ACCESS</li>
<li> NO_BUFFER</li>
<li> NO_MONITORING</li>
<li> NO_PUSH_PRED</li>
<li> NO_PUSH_SUBQ</li>
<li> NO_QKN_BUFF</li>
<li> NO_SEMIJOIN</li>
<li> NOAPPEND</li>
<li> NOCACHE</li>
<li> OR_EXPAND</li>
<li> ORDERED</li>
<li> ORDERED_PREDICATES</li>
<li> PUSH_PRED</li>
<li> PUSH_SUBQ</li>
<li> <span style="text-decoration: underline;">QB_NAME</span></li>
<li> <span style="text-decoration: underline;">RESULT_CACHE</span> (<span style="text-decoration: underline;">Oracle 11g</span>)</li>
<li> SELECTIVITY</li>
<li> SEMIJOIN</li>
<li> SEMIJOIN_DRIVER</li>
<li> STAR<br />
The STAR hint forces a star query plan to be used, if possible. A star plan has the largest table in the query last in the join order and joins it with a nested loops join on a concatenated index. The STAR hint applies when there are at least three tables, the large table&#8217;s concatenated index has at least three columns, and there are no conflicting access or join method hints. The optimizer also considers different permutations of the small tables.</li>
<li> SWAP_JOIN_INPUTS</li>
<li> USE_ANTI</li>
<li> USE_SEMI</li>
</ul>
<p><strong>Undocumented hints:</strong></p>
<ul class="unIndentedList">
<li> BYPASS_RECURSIVE_CHECK<br />
Workaraound for bug 1816154</li>
<li> BYPASS_UJVC</li>
<li> CACHE_CB</li>
<li> CACHE_TEMP_TABLE</li>
<li> CIV_GB</li>
<li> COLLECTIONS_GET_REFS</li>
<li> CUBE_GB</li>
<li> CURSOR_SHARING_EXACT</li>
<li> DEREF_NO_REWRITE</li>
<li> DML_UPDATE</li>
<li> DOMAIN_INDEX_NO_SORT</li>
<li> DOMAIN_INDEX_SORT</li>
<li> DYNAMIC_SAMPLING</li>
<li> DYNAMIC_SAMPLING_EST_CDN</li>
<li> EXPAND_GSET_TO_UNION</li>
<li> FORCE_SAMPLE_BLOCK</li>
<li> GBY_CONC_ROLLUP</li>
<li> GLOBAL_TABLE_HINTS</li>
<li> HWM_BROKERED</li>
<li> IGNORE_ON_CLAUSE</li>
<li> IGNORE_WHERE_CLAUSE</li>
<li> INDEX_RRS</li>
<li> INDEX_SS</li>
<li> INDEX_SS_ASC</li>
<li> INDEX_SS_DESC</li>
<li> LIKE_EXPAND</li>
<li> LOCAL_INDEXES</li>
<li> MV_MERGE</li>
<li> NESTED_TABLE_GET_REFS</li>
<li> NESTED_TABLE_SET_REFS</li>
<li> NESTED_TABLE_SET_SETID</li>
<li> NO_FILTERING</li>
<li> NO_ORDER_ROLLUPS</li>
<li> NO_PRUNE_GSETS</li>
<li> NO_STATS_GSETS</li>
<li> NO_UNNEST</li>
<li> NOCPU_COSTING</li>
<li> OVERFLOW_NOMOVE</li>
<li> PIV_GB</li>
<li> PIV_SSF</li>
<li> PQ_MAP</li>
<li> PQ_NOMAP</li>
<li> REMOTE_MAPPED</li>
<li> RESTORE_AS_INTERVALS</li>
<li> SAVE_AS_INTERVALS</li>
<li> SCN_ASCENDING</li>
<li> SKIP_EXT_OPTIMIZER</li>
<li> SQLLDR</li>
<li> SYS_DL_CURSOR</li>
<li> SYS_PARALLEL_TXN</li>
<li> SYS_RID_ORDER</li>
<li> TIV_GB</li>
<li> TIV_SSF</li>
<li> UNNEST</li>
<li> USE_TTT_FOR_GSETS</li>
</ul>
<div class="printfriendly alignleft"><a href="http://www.oratraining.com/blog/2009/04/oracle-sql-hints/?pfstyle=wp" rel="nofollow" ><img src="//cdn.printfriendly.com/pf-button-both.gif" alt="Print Friendly" /></a></div><div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Oracle+SQL+hints+http%3A%2F%2Foratraining.com%2Fblog%2F%3Fp%3D89" title="Post to Twitter"><img class="nothumb" src="http://www.oratraining.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big3.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.oratraining.com/blog/2009/04/oracle-sql-hints/&amp;title=Oracle+SQL+hints" title="Post to Digg"><img class="nothumb" src="http://www.oratraining.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg-big4.png" alt="Post to Digg" /></a></p></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.oratraining.com%2Fblog%2F2009%2F04%2Foracle-sql-hints%2F&amp;title=Oracle%20SQL%20hints" id="wpa2a_6"><img src="http://www.oratraining.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.oratraining.com/blog/2009/04/oracle-sql-hints/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

