<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-30275011</id><updated>2011-09-19T11:35:32.914-07:00</updated><category term='Result_Cache'/><category term='queues'/><category term='performance'/><category term='rank'/><category term='Oracle 11g'/><category term='caching'/><category term='AQ'/><category term='row_num'/><title type='text'>orabase</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://orabase.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>89</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-30275011.post-5889992689475905671</id><published>2011-09-19T11:30:00.000-07:00</published><updated>2011-09-19T11:35:32.950-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='row_num'/><category scheme='http://www.blogger.com/atom/ns#' term='rank'/><title type='text'>Dense Rank -Vs- Rank -Vs- Row_Number</title><content type='html'>&lt;div&gt;Rank =&amp;gt; Rank with Gaps (Eg: 1,2,2,4,5)&lt;/div&gt;Dense Rank =&amp;gt; Rank without Gaps (Eg: 1,2,2,3,4)&lt;div&gt;Row_Number =&amp;gt; Ordering of rows; no consideration of equal ranks (Eg: 1,2,3,4,5)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Rank over (ORDER BY clause)&lt;/div&gt;&lt;div&gt;Dense_rank over (ORDER BY clause)&lt;/div&gt;&lt;div&gt;Row_number over (ORDER BY clause)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ORDER BY clause can also be replaced by "PARTITION BY x ORDER BY y"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For details see the example here&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.adp-gmbh.ch/ora/sql/analytical/dense_rank_vs_rank_vs_row_number.html"&gt;http://www.adp-gmbh.ch/ora/sql/analytical/dense_rank_vs_rank_vs_row_number.html&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-5889992689475905671?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/5889992689475905671'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/5889992689475905671'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2011/09/dense-rank-vs-rank-vs-rownumber.html' title='Dense Rank -Vs- Rank -Vs- Row_Number'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-3351396223146307673</id><published>2009-01-27T14:33:00.000-08:00</published><updated>2009-01-27T14:50:20.030-08:00</updated><title type='text'>Analytic Function: Lag</title><content type='html'>Lag: Analytic function to retrieve a value from the previous row.&lt;br /&gt;&lt;br /&gt;Usage:&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Lag([column]) OVER (PARTITION BY [partition_column] ORDER BY [ordering_column])&lt;br /&gt;&lt;/ordering_column&gt;&lt;/partition_column&gt;&lt;/column&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;column - column to be pulled in from the previous row&lt;br /&gt;ordering_column - column by which a partition will be ordered&lt;br /&gt;partition_column - column to be used to partition data. On first thought it might seem that this column can as well be included in the ordering_column list. On careful inspection one may notice that doing so can result in incorrect data. Suppose the requirement is not just to pull data from any previous row; rather only rows belonging to the same class as the current row; in such a case including the partition_column under ordering_column will produce an incorrect result.&lt;br /&gt;&lt;br /&gt;Eg: See below example: Fetching transaction amounts for customers over a two months: Here the data needs to be partitioned by the customer and then the previous row may be pulled in.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CREATE TABLE tmp828cust(month date, custno number, cust_name varchar2(50))&lt;br /&gt;CREATE TABLE tmp828transact(month date, transactno number, custno number, amount number)&lt;br /&gt;&lt;br /&gt;Required output:&lt;br /&gt;CUSTNO CUST_NAME  TOTAL-MONTH1  TOTAL-MONTH2&lt;br /&gt;    1        A         5000          5500&lt;br /&gt;    2        B         1000           500&lt;br /&gt;    3        C         2000          1800&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Inefficient Solution&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SELECT t1.custno,&lt;br /&gt;       t1.cust_name,&lt;br /&gt;       t1.tot,&lt;br /&gt;       t2.tot&lt;br /&gt;  FROM&lt;br /&gt;(&lt;br /&gt;SELECT c.custno,&lt;br /&gt;       c.cust_name,&lt;br /&gt;       Sum(t.amount) tot&lt;br /&gt;  FROM tmp828cust c,&lt;br /&gt;       tmp828transact t&lt;br /&gt; WHERE c.month = t.month&lt;br /&gt;   AND c.custno = t.custno&lt;br /&gt;   AND t.MONTH = '01-JAN-2008'&lt;br /&gt; GROUP BY c.custno, c.cust_name&lt;br /&gt;)t1,&lt;br /&gt;(&lt;br /&gt;SELECT c.custno,&lt;br /&gt;       c.cust_name,&lt;br /&gt;       Sum(t.amount) tot&lt;br /&gt;  FROM tmp828cust c,&lt;br /&gt;       tmp828transact t&lt;br /&gt; WHERE c.month = t.month&lt;br /&gt;   AND c.custno = t.custno&lt;br /&gt;   AND t.MONTH = '01-FEB-2008'&lt;br /&gt; GROUP BY c.custno, c.cust_name&lt;br /&gt;)t2&lt;br /&gt;WHERE t1.custno = t2.custno&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Better Solution&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SELECT *&lt;br /&gt;  FROM (SELECT custno,&lt;br /&gt;               cust_name,&lt;br /&gt;               month,&lt;br /&gt;               amt,&lt;br /&gt;               Lag(amt) OVER (PARTITION BY custno ORDER BY month) last_amt&lt;br /&gt;         FROM (SELECT t.month,&lt;br /&gt;                      c.custno,&lt;br /&gt;                      c.cust_name,&lt;br /&gt;                      Sum(t.amount) amt&lt;br /&gt;                 FROM tmp828cust c,&lt;br /&gt;                      tmp828transact t&lt;br /&gt;                WHERE c.month = t.month&lt;br /&gt;                  AND c.custno = t.custno&lt;br /&gt;                GROUP BY t.month,&lt;br /&gt;                         c.custno,&lt;br /&gt;                         c.cust_name&lt;br /&gt;              )&lt;br /&gt;        )&lt;br /&gt; WHERE last_amt IS NOT NULL&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Notice the usage of Lag function &lt;/partition_column&gt;&lt;/column&gt;here&lt;br /&gt;Lag(amt) OVER (PARTITION BY custno ORDER BY month) : Get the amt column from the previous row, rows should be Partitioned by custno and Ordered by month&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;1. &lt;a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1396477600346947904"&gt;http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1396477600346947904&lt;/a&gt;&lt;br /&gt;2. &lt;a href="http://www.adp-gmbh.ch/ora/sql/analytical/lag.html"&gt;http://www.adp-gmbh.ch/ora/sql/analytical/lag.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-3351396223146307673?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/3351396223146307673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/3351396223146307673'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2009/01/analytic-function-lag.html' title='Analytic Function: Lag'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-8547676319341983256</id><published>2007-10-23T16:49:00.000-07:00</published><updated>2007-10-23T16:52:19.079-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AQ'/><category scheme='http://www.blogger.com/atom/ns#' term='queues'/><title type='text'>Oracle AQ</title><content type='html'>Here's a &lt;a href="http://www.akadia.com/services/ora_advanced_queueing.html"&gt;good article&lt;/a&gt; on Oracle Advanced Queues (AQ). The article talks about the basics of a queue and goes on to explain how this is implemented in Oracle's AQ. There's also a basic explanation about Oracle's JMS interface to AQ.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.akadia.com/services/ora_advanced_queueing.html"&gt;http://www.akadia.com/services/ora_advanced_queueing.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-8547676319341983256?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/8547676319341983256'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/8547676319341983256'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2007/10/oracle-aq.html' title='Oracle AQ'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-2167153669638954251</id><published>2007-08-23T21:39:00.000-07:00</published><updated>2007-08-23T21:51:15.712-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='performance'/><category scheme='http://www.blogger.com/atom/ns#' term='caching'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle 11g'/><category scheme='http://www.blogger.com/atom/ns#' term='Result_Cache'/><title type='text'>Result_Cache in Oracle 11g</title><content type='html'>One interesting feature in Oracle 11g database is result caching. To reduce disk I/O, oracle already caches data blocks. With result caching, this is taken one step ahead - results of a query are cached in memory so that  a repeat evaluation is not required. So if you have a common SQL being executed in your application, Oracle 11g does the caching for you. And this caching does not compromise on data integrity - whenever a DML operation is performed on a dependant table, the result cache is invalidated.&lt;br /&gt;&lt;br /&gt;As Tom says, Result_Cache is more like a Just-In-Time Materialized View - an MV which does not require DBA intervention&lt;br /&gt;&lt;br /&gt;For examples usages of Result_Cache click &lt;a href="http://www.oracle.com/technology/oramag/oracle/07-sep/o57asktom.html"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-2167153669638954251?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/2167153669638954251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/2167153669638954251'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2007/08/resultcache-in-oracle-11g.html' title='Result_Cache in Oracle 11g'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-2935510569480503565</id><published>2007-07-02T12:26:00.000-07:00</published><updated>2007-07-04T12:04:50.128-07:00</updated><title type='text'>Why are COMMIT times generally flat?</title><content type='html'>&lt;span style="font-family:verdana;"&gt;Contrary to intuitive reasoning, COMMIT is an operation which is not dependant on the size of the transaction (a more or less flat CommitTime-Vs-Volume chart). The reason behind this is that even before the COMMIT is issued, most of the volume dependant operations have been completed (Modifying data blocks in SGA, undo block generation, redo information generation etc). When a COMMIT is issued, the following operations are performed&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;1. Generate an SCN for the transaction&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;2. Write remaining buffered redo log entries to disk and record  the SCN (lengthiest operation).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;3. Release any locks that were acquired as part of the transaction.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Hence COMMIT time is not affected by the size of the transaction. Now thats why wise men say - Never issue COMMITs in a loop (of course, unless each iteration is required to be an atomic transactions in itself!).&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-2935510569480503565?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/2935510569480503565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/2935510569480503565'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2007/07/why-are-commit-times-generally-flat.html' title='Why are COMMIT times generally flat?'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-6614007535950752844</id><published>2007-06-01T21:53:00.000-07:00</published><updated>2007-06-01T22:04:48.146-07:00</updated><title type='text'>Join Types - NestedLoop, HashJoin, SortMerge</title><content type='html'>&lt;span style="font-weight: bold;font-family:verdana;" &gt;Nested Loop Join&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;============&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; &lt;span style="font-style: italic;"&gt;Outer Loop&lt;/span&gt; : Row source 1 is scanned (outer /driving table)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; &lt;span style="font-style: italic;"&gt;Inner Loop&lt;/span&gt; : Each row returned drives a lookup in row source 2 (inner)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; Joining rows are then returned&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-style: italic;"&gt; Cost&lt;/span&gt;: Read driving table and access on inner table.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; Performance is very dependent on index on inner table&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Optimizer uses nested loop when we are joining tables containing small number of rows with an efficient driving condition. It is important to have an index on column of inner join table as this table is probed every time for a new value from outer table.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Hash Join&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;=======&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; In theory - the most efficient joint method. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-style: italic;"&gt; Build Phase&lt;/span&gt;: The smaller row source is used to build a hash table and a bitmap&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-style: italic;"&gt; Probe Phase&lt;/span&gt;: The second row source is hashed and checked against the hash table&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; The bitmap is used as a quick lookup to check if rows are in the hash table.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; It requires single pass for each row source , and more efficient than sorting and merging&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; Optimizer uses has join while joining big tables or big fraction of small tables.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;SortMerge Join&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;===========&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-style: italic;"&gt; Sort Phase  &lt;/span&gt;: Rows from source 1 are sorted; Rows from source 2 are then sorted by the same sort key&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-style: italic;"&gt; Merge Phase&lt;/span&gt; : Sorted rows from both sides are then merged&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-style: italic;"&gt; Cost        &lt;/span&gt;: sorting, reading tables, I/O for temporary segments&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Optmizer choose SM Join in following cases&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;a) When the join condition is an inequality condition (like &lt;, &lt;=, &gt;=). This is because hash join cannot be used for inequality conditions and if the data set is large, nested loop is definitely not an option.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;b) If sorting is anyways required due to some other attribute (other than join) like “order by”, optimizer prefers sort merge join over hash join as it is cheaper.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;More Info:&lt;br /&gt;&lt;a href="http://www.blogger.com/www.oraclenotes.com/Articles/Optimizer%20and%20CBO.ppt"&gt;www.oraclenotes.com/Articles/Optimizer%20and%20CBO.ppt&lt;/a&gt;&lt;br /&gt;&lt;a href="http://oracle-online-help.blogspot.com/2007/03/nested-loops-hash-join-and-sort-merge.html"&gt;http://oracle-online-help.blogspot.com/2007/03/nested-loops-hash-join-and-sort-merge.html&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-6614007535950752844?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/6614007535950752844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/6614007535950752844'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2007/06/join-types-nestedloop-hashjoin.html' title='Join Types - NestedLoop, HashJoin, SortMerge'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-6556883452590729153</id><published>2007-03-30T23:35:00.000-07:00</published><updated>2007-03-30T23:37:07.655-07:00</updated><title type='text'>LSNRCTL</title><content type='html'>&lt;span style="font-family: verdana;"&gt;LSNRCTL is a utility to manage Oracle's listener processes.  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;What does the listener do? &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The Oracle listener process is required for database applications to access the database through SQL*Net or Net8.  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * listens for requests on a specific port&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * spawns or requests a database process/thread&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * redirects or passes the connection to the process/thread&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Config File for the Listener -&gt; listener.ora&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;What does listener.org contain?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The listener.ora file resides on the server and defines&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;a. network listener address&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;b. SID for the database for which it listens&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;c. optional parameters for tracing and logging&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-6556883452590729153?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/6556883452590729153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/6556883452590729153'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2007/03/lsnrctl.html' title='LSNRCTL'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-8506986958701903191</id><published>2007-02-01T00:55:00.000-08:00</published><updated>2007-02-01T01:07:28.576-08:00</updated><title type='text'>Partitioned tables/indexes</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Partitioned tables/indexes are useful in VLDBs (Very Large DataBase); partitioned tables/indexes are divided into a number of pieces, or partitions, which have the same logical attributes. For example, all partitions in a table share the same column and constraint definitions, and all partitions in an index share the same index options. Each partition is stored in a separate segment and can have different physical attributes (such as PCTFREE, PCTUSED, INITRANS, MAXTRANS, TABLESPACE, and STORAGE).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Although you are not required to keep each table or index partition in a separate tablespace, it is to your advantage to do so. Storing partitions in separate tablespaces can:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * reduce the possibility of data corruption in multiple partitions&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * make it possible to back up and recover each partition independently&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * make it possible to control the mapping of partitions to disk drives (important for balancing I/O load)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;There are several partitioning methods offered by Oracle:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Range partitioning&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Hash partitioning&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * List partitioning&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Composite range-hash partitioning&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Composite range-list partitioning&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. When creating range partitions, you must specify:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Partitioning method: range&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Partitioning column(s)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Partition descriptions identifying partition bounds&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The example below creates a table of four partitions, one for each quarter's sales. The columns sale_year, sale_month, and sale_day are the partitioning columns, while their values constitute a specific row's partitioning key. The VALUES LESS THAN clause determines the partition bound: rows with partitioning key values that compare less than the ordered list of values specified by the clause are stored in the partition. Each partition is given a name (sales_q1, sales_q2, ...), and each partition is contained in a separate tablespace (tsa, tsb, ...).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CREATE TABLE sales&lt;br /&gt;   ( invoice_no NUMBER,&lt;br /&gt;     sale_year  INT NOT NULL,&lt;br /&gt;     sale_month INT NOT NULL,&lt;br /&gt;     sale_day   INT NOT NULL )&lt;br /&gt; PARTITION BY RANGE (sale_year, sale_month, sale_day)&lt;br /&gt;   ( PARTITION sales_q1 VALUES LESS THAN (1999, 04, 01)&lt;br /&gt;       TABLESPACE tsa,&lt;br /&gt;     PARTITION sales_q2 VALUES LESS THAN (1999, 07, 01)&lt;br /&gt;       TABLESPACE tsb,&lt;br /&gt;     PARTITION sales_q3 VALUES LESS THAN (1999, 10, 01)&lt;br /&gt;       TABLESPACE tsc,&lt;br /&gt;     PARTITION sales_q4 VALUES LESS THAN (2000, 01, 01)&lt;br /&gt;       TABLESPACE tsd );&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;A row with sale_year=1999, sale_month=8, and sale_day=1 has a partitioning key of (1999, 8, 1) and would be stored in partition sales_q3.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. To create hash partitions you specify the following:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Partitioning method: hash&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Partitioning columns(s)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Number of partitions or individual partition descriptions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The following example creates a hash-partitioned table. The partitioning column is id, four partitions are created and assigned system generated names, and they are placed in four named tablespaces (gear1, gear2, ...).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CREATE TABLE scubagear&lt;br /&gt;    (id NUMBER,&lt;br /&gt;     name VARCHAR2 (60))&lt;br /&gt;  PARTITION BY HASH (id)&lt;br /&gt;  PARTITIONS 4&lt;br /&gt;  STORE IN (gear1, gear2, gear3, gear4);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. When creating list partitions, you must specify:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Partitioning method: list&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Partitioning column&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Partition descriptions, each specifying a list of literal values (a value list), which are the discrete values of the partitioning column that qualify a row to be included in the partition&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The following example creates a list-partitioned table. It creates table q1_sales_by_region which is partitioned by regions consisting of groups of states.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CREATE TABLE q1_sales_by_region&lt;br /&gt;     (deptno number,&lt;br /&gt;      deptname varchar2(20),&lt;br /&gt;      quarterly_sales number(10, 2),&lt;br /&gt;      state varchar2(2))&lt;br /&gt;  PARTITION BY LIST (state)&lt;br /&gt;     (PARTITION q1_northwest VALUES ('OR', 'WA'),&lt;br /&gt;      PARTITION q1_southwest VALUES ('AZ', 'UT', 'NM'),&lt;br /&gt;      PARTITION q1_northeast VALUES  ('NY', 'VM', 'NJ'),&lt;br /&gt;      PARTITION q1_southeast VALUES ('FL', 'GA'),&lt;br /&gt;      PARTITION q1_northcentral VALUES ('SD', 'WI'),&lt;br /&gt;      PARTITION q1_southcentral VALUES ('OK', 'TX'));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;a href="http://www.pitt.edu/AFShome/h/o/hoffman/public/html/oradoc/server.804/a58397/ch11.htm"&gt;http://www.pitt.edu/AFShome/h/o/hoffman/public/html/oradoc/server.804/a58397/ch11.htm&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-8506986958701903191?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/8506986958701903191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/8506986958701903191'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2007/02/partitioned-tablesindexes.html' title='Partitioned tables/indexes'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-4056207405740844153</id><published>2007-01-26T05:44:00.000-08:00</published><updated>2007-01-26T05:56:27.025-08:00</updated><title type='text'>The ROW_NUMBER() Function</title><content type='html'>&lt;span style="font-family:verdana;"&gt;ROW_NUMBER( ) is an Analytic Function which can be used to assign a running serial number to a '&lt;span style="font-style: italic;"&gt;partition&lt;/span&gt;' of records. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ROWNUM gives a running count for the entire result set. ROW_NUMBER() on the other hand assigns a running count for partitioned sets within the entire result set. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Eg: Suppose you need to have a partitioned numbering which will assign running serial number to employees in each department.&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SELECT empno,&lt;br /&gt;     deptno,&lt;br /&gt;     hiredate,&lt;br /&gt;     ROW_NUMBER( ) OVER (PARTITION BY deptno ORDER BY hiredate NULLS LAST) SRLNO&lt;br /&gt;FROM emp&lt;br /&gt;WHERE deptno IN (10, 20)&lt;br /&gt;ORDER BY deptno, SRLNO;&lt;br /&gt;&lt;br /&gt;EMPNO  DEPTNO HIREDATE       SRLNO&lt;br /&gt;------ ------- --------- ----------&lt;br /&gt;7782      10 09-JUN-81          1&lt;br /&gt;7839      10 17-NOV-81          2&lt;br /&gt;7934      10 23-JAN-82          3&lt;br /&gt;7369      20 17-DEC-80          1&lt;br /&gt;7566      20 02-APR-81          2&lt;br /&gt;7902      20 03-DEC-81          3&lt;br /&gt;7788      20 09-DEC-82          4&lt;br /&gt;7876      20 12-JAN-83          5&lt;br /&gt;&lt;br /&gt;8 rows selected.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;With Excerpts from: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://orafaq.com/node/55"&gt;http://orafaq.com/node/55&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-4056207405740844153?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/4056207405740844153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/4056207405740844153'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2007/01/rownumber-function.html' title='The ROW_NUMBER() Function'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-116781719616032062</id><published>2007-01-03T01:31:00.000-08:00</published><updated>2007-01-03T01:39:56.690-08:00</updated><title type='text'>Cursors - Vs - Ref Cursors</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Here are couple of differences between Cursors and Ref Cursors&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. A "normal" plsql cursor is static in defintion. Ref cursors may be dynamically opened or opened based on logic.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Declare&lt;br /&gt;  type rc is ref cursor;&lt;br /&gt; &lt;br /&gt;  cursor c is select * from dual;&lt;br /&gt;&lt;br /&gt;  l_cursor rc;&lt;br /&gt;begin&lt;br /&gt;  if ( to_char(sysdate,'dd') = 30 ) then&lt;br /&gt;    open l_cursor for 'select * from emp';&lt;br /&gt;  elsif ( to_char(sysdate,'dd') = 29 ) then&lt;br /&gt;    open l_cursor for select * from dept;&lt;br /&gt;  else&lt;br /&gt;    open l_cursor for select * from dual;&lt;br /&gt;  end if;&lt;br /&gt;  open c;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Given that block of code -- you see perhaps the most "salient" difference -- no &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;matter how many times you run that block -- cursor C will always be&lt;/span&gt; &lt;span style="font-family: courier new;"&gt;select * &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;from dual&lt;/span&gt;.  &lt;span style="font-family: verdana;"&gt;The ref cursor can be anything.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Another difference is a ref cursor can be returned to a client.  a plsql "cursor &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;cursor" cannot be returned to a client. Also, a ref cursor can be passed from subroutine to subroutine -- a cursor cannot be.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Another difference is a cursor can be global -- a ref cursor cannot (you cannot &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;define them OUTSIDE of a procedure / function)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Static sql (not using a ref cursor) is much more &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;efficient then using ref cursors and that use of ref cursors should be limited &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;to&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;- returning result sets to clients&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;- when there is NO other efficient/effective means of achieving the goal&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;that is, you want to use static SQL (with implicit cursors really) first and use &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;a ref cursor only when you absolutely have to.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://asktom.oracle.com/pls/ask/f?p=4950:8:15205724112663115383::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:14188501024541"&gt;http://asktom.oracle.com/pls/ask/f?p=4950:8:15205724112663115383::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:14188501024541&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-116781719616032062?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/116781719616032062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/116781719616032062'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2007/01/cursors-vs-ref-cursors.html' title='Cursors - Vs - Ref Cursors'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-116364691692327945</id><published>2006-11-15T18:59:00.000-08:00</published><updated>2006-11-15T19:15:17.393-08:00</updated><title type='text'>Audit Trails in Oracle</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Audit trails allow the DBA to dig-up information regarding&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;* database access&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;* changes to the database structure&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;* failed log-on attempts&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;* attempts to access the database at unusual hours&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;* users sharing database accounts&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;* multiple access attempts for different users from the same terminal&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;* Insert/Update/Delete on tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Audit is turned on for writing to the database by adding the following line to the init.ora file. A symbolic link to it can usually be found in $ORACLE_HOME/dbs&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;audit_trail = db&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The database now needs to be restarted. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. A simple check will show that audit is indeed now turned on.&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SQL&gt; select name,value from v$parameter&lt;br /&gt; 2  where name like 'audit%';&lt;br /&gt;&lt;br /&gt;NAME                           VALUE&lt;br /&gt;------------------------------ ------------------------------&lt;br /&gt;audit_trail                    DB&lt;br /&gt;audit_file_dest                ?/rdbms/audit&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. No audit actions are captured yet until audit actions are defined; that is, except for privileged access to the database, starting and stopping of the database, and structural changes such as adding a datafile. These are logged to operating system files in $ORACLE_HOME/rdbms/audit unless audit_file_dest is redefined in the init.ora file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. To turn on audit for the access attempts to the database:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SQL&gt; audit create session;&lt;br /&gt;&lt;br /&gt;Audit succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. To find out what objects are being audited, query the view dba_obj_audit_opts.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;For a user to define audit statements, the privilege "AUDIT SYSTEM" needs to have been granted first. The users that have this privilege can be checked as follows:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SQL&gt; select *&lt;br /&gt; 2  from dba_sys_privs&lt;br /&gt; 3  where privilege like '%AUDIT%';&lt;br /&gt;&lt;br /&gt;GRANTEE                        PRIVILEGE                                ADM&lt;br /&gt;------------------------------ ---------------------------------------- ---&lt;br /&gt;CTXSYS                         AUDIT ANY                                NO&lt;br /&gt;CTXSYS                         AUDIT SYSTEM                             NO&lt;br /&gt;DBA                            AUDIT ANY                                YES&lt;br /&gt;DBA                            AUDIT SYSTEM                             YES&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://www.securityfocus.com/infocus/1689"&gt;http://www.securityfocus.com/infocus/1689&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-116364691692327945?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/116364691692327945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/116364691692327945'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/11/audit-trails-in-oracle.html' title='Audit Trails in Oracle'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-116225362176496653</id><published>2006-10-30T16:09:00.000-08:00</published><updated>2006-10-30T16:13:43.156-08:00</updated><title type='text'>When ROWNUM value is actually assigned</title><content type='html'>&lt;span style="font-family:verdana;"&gt;Tom Kyte explains this very well in a recent article on OTN. Excerpts below...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;1. ROWNUM value is assigned to a row after it passes the predicate phase of the query but before the query does any sorting or aggregation. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;2. A ROWNUM value is incremented only after it is assigned, which is why the following query will never return a row:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;select * &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;  from t &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; where ROWNUM &gt; 1;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Because ROWNUM &gt; 1 is not true for the first row, ROWNUM does not advance to 2. Hence, no ROWNUM value ever gets to be greater than 1.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;For a detailed article on ROWNUM check out &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html?rssid=rss_otn_articles"&gt;http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html?rssid=rss_otn_articles&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-116225362176496653?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/116225362176496653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/116225362176496653'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/10/when-rownum-value-is-actually-assigned.html' title='When ROWNUM value is actually assigned'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115985785071328232</id><published>2006-10-02T23:43:00.000-07:00</published><updated>2006-10-02T23:44:11.000-07:00</updated><title type='text'>Statspack</title><content type='html'>&lt;p&gt;&lt;span style="font-family:verdana;"&gt;Statspack is an oracle utility which allows a Datavase Administrator to compare how the DB was at two different points of time. Statspack does this by capturing two snapshots of the DB at two different points in time. When statspack is installed, it creates a PERFSTAT user which will own all statspack related database objects.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;pre class="code"&gt;&lt;br /&gt;To install statspack, run SPCREATE.sql&lt;br /&gt;SQL&gt;  @?/rdbms/admin/spcreate&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;To take a snapshot using statspack&lt;br /&gt;SQL&gt;  CONNECT perfstat/my_perfstat_passwordSQL&gt;  EXECUTE statspack.snap;&lt;br /&gt;&lt;/p&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;To automate the gathering of statistics&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;# Use DBMS_JOB procedure to schedule snapshots.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;# Use an operating system utility, such as cron on UNIX. On Windows platforms, you can use the at utility on Windows NT or System Tools &gt; Scheduled Tasks on Windows 2000.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;Creati&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;ng a Statspack Report Without Prompts (UNIX)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;pre class="code"&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;SQL&gt;  connect perfstat/my_perfstat_password&lt;/p&gt;&lt;p&gt;SQL&gt;  define begin_snap=1&lt;/p&gt;&lt;p&gt;SQL&gt;  define end_snap=2&lt;/p&gt;&lt;p&gt;SQL&gt;  define report_name=batch_run&lt;/p&gt;&lt;p&gt;SQL&gt;  @?/rdbms/admin/spreport&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:verdana;"&gt;With Excerpts from : &lt;/span&gt;&lt;a href="http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96533/statspac.htm#34837"&gt;&lt;span style="font-family:verdana;"&gt;http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96533/statspac.htm#34837&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115985785071328232?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115985785071328232'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115985785071328232'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/10/statspack.html' title='Statspack'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115942904108057913</id><published>2006-09-28T00:37:00.000-07:00</published><updated>2006-09-28T00:37:21.160-07:00</updated><title type='text'>Oracle Wait Interface</title><content type='html'>&lt;span style="font-family:verdana;"&gt;A Good Article which explains Oracle's wait interface&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.oracle.com/technology/pub/articles/schumacher_10gwait.html"&gt;http://www.oracle.com/technology/pub/articles/schumacher_10gwait.html&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115942904108057913?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115942904108057913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115942904108057913'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/09/oracle-wait-interface_28.html' title='Oracle Wait Interface'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115659227849518415</id><published>2006-08-26T04:31:00.000-07:00</published><updated>2006-08-26T04:39:30.946-07:00</updated><title type='text'>Removing large listener.log files</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Attempts to remove or rename the listener.log file while the TNS listener process is running throw errors, since the listener process would be holding a lock on it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Two solutions are&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Stop the TNS listener process, rename (or remove) the file, then restart the TNS listener process.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. A better solution which does not require the listener process to be stopped.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;C:\&gt; lsnrctl set log_status off&lt;br /&gt;&lt;br /&gt;Now rename/remove the log file&lt;br /&gt;&lt;br /&gt;C:\&gt; lsnrctl set log_status on&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;With excerpts from http://www.idevelopment.info/data/Oracle/DBA_tips/Networking/NET_3.shtml&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115659227849518415?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115659227849518415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115659227849518415'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/removing-large-listenerlog-files.html' title='Removing large listener.log files'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115607800476134881</id><published>2006-08-20T05:40:00.000-07:00</published><updated>2006-08-20T05:47:47.776-07:00</updated><title type='text'>Soundex Function</title><content type='html'>&lt;span style="font-family:verdana;"&gt;Given a String, the Soundex function returns a character string which is its Phonetic Representation. This is useful for performing "Sounds Like" comparisons.(See the example below)&lt;br /&gt;&lt;br /&gt;The Soundex algorithm is as follows:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;    * Retain the first letter of the string and remove all other occurrences of the following letters: a, e, h, i, o, u, w, y&lt;br /&gt;    * Assign numbers to the remaining letters (after the first) as&lt;br /&gt;      follows:&lt;br /&gt;      b, f, p, v = 1&lt;br /&gt;      c, g, j, k, q, s, x, z = 2&lt;br /&gt;      d, t = 3&lt;br /&gt;      l = 4&lt;br /&gt;      m, n = 5&lt;br /&gt;      r = 6&lt;br /&gt;    * If two or more letters with the same number were adjacent in the original name (before step 1), or adjacent except for any intervening h and w, then omit all but the first.&lt;br /&gt;    * Return the first four bytes padded with 0.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The soundex function uses only the first 5 consonants to determine the NUMERIC portion of the return value, except if the first letter of string1 is a vowel. The soundex function is not case-sensitive. ie. both uppercase and lowercase characters will generate the same soundex return value.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;&lt;br /&gt;Syntax:&lt;br /&gt;SOUNDEX(&lt;string&gt;&lt;string_or_column&gt;)&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;CREATE TABLE test123&lt;br /&gt; (name VARCHAR2(15));&lt;br /&gt;&lt;br /&gt;INSERT INTO test123 VALUES ('Smith');&lt;br /&gt;INSERT INTO test123 VALUES ('Smyth');&lt;br /&gt;INSERT INTO test123 VALUES ('Smythe');&lt;br /&gt;INSERT INTO test123 VALUES ('Smither');&lt;br /&gt;INSERT INTO test123 VALUES ('Smidt');&lt;br /&gt;INSERT INTO test123 VALUES ('Smick');&lt;br /&gt;INSERT INTO test123 VALUES ('Smiff');&lt;br /&gt;COMMIT;&lt;br /&gt;&lt;br /&gt;SELECT * FROM test123;&lt;br /&gt;&lt;br /&gt;SELECT SOUNDEX(NAME), NAME&lt;br /&gt;FROM test123&lt;br /&gt;WHERE SOUNDEX(name) = SOUNDEX('SMITH');&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Source:&lt;br /&gt;&lt;a href="http://www.psoug.org/reference/string_func.html"&gt;http://www.psoug.org/reference/string_func.html&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.techonthenet.com/oracle/functions/soundex.php"&gt;http://www.techonthenet.com/oracle/functions/soundex.php&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115607800476134881?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115607800476134881'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115607800476134881'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/soundex-function.html' title='Soundex Function'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115607239375048369</id><published>2006-08-20T04:10:00.000-07:00</published><updated>2006-08-20T04:15:25.853-07:00</updated><title type='text'>Loopback Adapters for Oracle Installation in DHCP Networks</title><content type='html'>&lt;span style="font-family:verdana;"&gt;Dynamic Host Configuration Protocol (DHCP) assigns dynamic IP addresses on a network. Dynamic addressing allows a computer to have a different IP address each time it connects to the network. In some cases, the IP address can change while the computer is still connected. You can have a mixture of static and dynamic IP addressing in a DHCP system.&lt;br /&gt;&lt;br /&gt;In a DHCP setup, the software tracks IP addresses, which simplifies network administration. This lets you add a new computer to the network without having to manually assign that computer a unique IP address. However, before installing Oracle Database onto a computer that uses the DHCP protocol, you need to install a loopback adapter to assign a local IP address to that computer.&lt;br /&gt;&lt;br /&gt;Loopback adapter approach is recommended particularly for laptops (presumably used only for learning purposes!) which connect and disconnect from the real, corporate network. The loopback adapter means that Oracle will function regardless of whether the laptop is connected to the network or not: it gives Oracle a static, always-there, point of reference independent of what shenannigans the real NIC gets up to.&lt;br /&gt;&lt;br /&gt;To install a loopback adapter on Windows XP:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;   1.      From the Start menu, select Control Panel.&lt;br /&gt;   2.      Double-click Add Hardware to start the Add Hardware wizard.&lt;br /&gt;   3.      On the Welcome screen, click Next.&lt;br /&gt;   4.      On the Is the hardware connected? screen, select Yes, I have already connected the hardware, and click Next.&lt;br /&gt;   5.      On the The following hardware is already installed on your computer screen, select Add a new hardware device, and click Next.&lt;br /&gt;   6.      On the The wizard can help you install other hardware screen, select Install the hardware that I manually select from a list, and click Next.&lt;br /&gt;   7.      From the list, select the type of hardware you are installing screen, select Network adapters, and click Next.&lt;br /&gt;   8.      On the Select Network Adapter screen, make the following selections:&lt;br /&gt;          *            Manufacturer: select Microsoft.&lt;br /&gt;          *            Network Adapter: select Microsoft Loopback Adapter.&lt;br /&gt;   9.      Click Next.&lt;br /&gt;  10.      On the The wizard is ready to install your hardware screen, click Next.&lt;br /&gt;  11.      On the Completing the Add Hardware Wizard screen, click Finish.&lt;br /&gt;  12.      If you are using Windows 2003, restart your computer.&lt;br /&gt;  13.      Right-click My Network Places on the desktop and choose Properties. This displays the Network Connections control panel.&lt;br /&gt;  14.      Right-click the connection that was just created. This is usually named "Local Area Connection 2". Choose Properties.&lt;br /&gt;  15.      On the General tab, select Internet Protocol (TCP/IP), and click Properties.&lt;br /&gt;  16.      In the Properties dialog, do the following:&lt;br /&gt;         1.            IP Address: Enter a non-routable IP for the loopback adapter. Oracle recommends the following non-routable addresses:&lt;br /&gt;                *                  192.168.x.x (x is any value between 1 and 255)&lt;br /&gt;                *                  10.10.10.10&lt;br /&gt;         2.            Subnet mask: Enter 255.255.255.0.&lt;br /&gt;         3.            Leave all other fields empty.&lt;br /&gt;         4.            Click OK.&lt;br /&gt;  17.      Click OK.&lt;br /&gt;  18.      Click OK in the Local Area Connection 2 Properties dialog.&lt;br /&gt;  19.      Restart the computer.&lt;br /&gt;  20.      Add a line to the C:\windows\system32\drivers\etc\hosts file with the following format, after the localhost line:&lt;br /&gt;&lt;br /&gt;      IP_address   hostname.domainname   hostname&lt;br /&gt;&lt;br /&gt;      where:&lt;br /&gt;          *            IP_address is the non-routable IP address you entered in step 16.&lt;br /&gt;          *            hostname is the name of the computer.&lt;br /&gt;          *            domainname is the name of the domain.&lt;br /&gt;&lt;br /&gt;      For example:&lt;br /&gt;&lt;br /&gt;      10.10.10.10   mycomputer.mydomain.com   mycomputer&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  21.      Check the network configuration:&lt;br /&gt;         1.            Open System Properties, and select the Computer Name tab. In Full computer name, make sure you see the hostname and the domain name.&lt;br /&gt;         2.            Click Change. In Computer name, you should see the hostname, and in Full computer name, you should see the hostname and domain name.&lt;br /&gt;         3.            Click More. In Primary DNS suffix of this computer, you should see the domain name.&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Source:&lt;br /&gt;&lt;a href="http://www.dizwell.com/prod/node/71"&gt;http://www.dizwell.com/prod/node/71&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://download-west.oracle.com/docs/html/B10130_02/reqs.htm#BABDJJFF"&gt;http://download-west.oracle.com/docs/html/B10130_02/reqs.htm#BABDJJFF&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115607239375048369?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115607239375048369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115607239375048369'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/loopback-adapters-for-oracle.html' title='Loopback Adapters for Oracle Installation in DHCP Networks'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115497889116781729</id><published>2006-08-07T12:24:00.000-07:00</published><updated>2006-08-07T12:28:11.650-07:00</updated><title type='text'>Oracle PFile and SPFile</title><content type='html'>&lt;span style="font-family: verdana;"&gt;In Oracle Databases through 8i, parameters controling memory, processor usage, control file locations and other key parameters are kept in a pfile (short for parameter file).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The pfile is a static, plain text files which can be altered using a text editor, but it is only read at database startup. Any changes to the pfile will not be read until the database is restarted and any changes to a running database will not be written to the pfile.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Due to these limitations, in 9i Oracle introduced the spfile (server parameter file). The spfile cannot be edited by the DBA; instead it is updated by using ALTER SYSTEM commands from within Oracle. This allows parameter changes to be persistent across database restarts, but can leave you in a pinch if you need to change a parameter to get a database started but you need the database running to change the parameter.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;A 9i (or later) database can have either a pfile or an spfile, or even both, but how can you tell which you have? If you have both, which one is being used? How do you go from one to the other? How do you get out of the chicken-and-the-egg quandary of a database that will not start up without you changing a parameter that’s in that file you can’t update unless the database is up?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Note: This information is based on an Oracle 9i installation on Solaris. Your mileage may vary. I have also chosen to ignore issues of RAC installation. In my example I have used ORADB as my SID.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;Am I using a pfile or an spfile?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The first thing to check is if you have a pfile or spfile. They can be specified at startup or found in the default location. The default path for the pfile is $ORACLE_HOME/dbs/init$ORACLE_SID.ora and the default for the spfile is $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If both a pfile and an spfile exist in their default location and the database is started without a pfile='/path/to/init.ora' then the spfile will be used.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Assuming your database is running you can also check the spfile parameter. Either the command SHOW PARAMETER spfile or SELECT value FROM v$parameter WHERE name='spfile'; will return the path to the spfile if you are using one. If the value of spfile is blank you are not using an spfile.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The path to the spfile will often be represented in the database by ?/dbs/spfile@.ora. This may seem cryptic, but Oracle translates ? to $ORACLE_HOME and @ to $ORACLE_SID so this string translates to the default location of the spfile for this database.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;How can I create an spfile from a pfile?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;As long as your pfile is in the default locations and you want your spfile in the default location, you can easily create an spfile with the command CREATE SPFILE FROM PFILE;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If you need to be more specific about the locations you can add paths to the create command like this:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CREATE SPFILE='/u01/app/oracle/product/9.2/dbs/spfileORADB.ora'&lt;br /&gt;FROM PFILE=’/u01/app/oracle/product/9.2/dbs/initORADB.ora’;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;These commands should work even when the database is not running! This is important when you want to change a database to use an spfile before you start it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;How can I create a pfile from an spfile?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The commands for creating a pfile are almost identical to those for creating a spfile except you reverse the order of spfile and pfile:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If your pfile is in the default location and you want your spfile created there as well run CREATE SPFILE FROM PFILE;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If you have, or want them in custom locations specify the paths like this:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CREATE PFILE='/u01/app/oracle/product/9.2/dbs/initORADB.ora'&lt;br /&gt;FROM SPFILE=’/u01/app/oracle/product/9.2/dbs/spfileORADB.ora’;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Again, this can be done without the database running. This is useful when the database fails to start due to a parameter set in the spfile. This is also a good step to integrate into your backup procedures.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;How can I see what’s in my spfile&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;To view the settings in the spfile we have two options: First, we can use the command above to create a pfile from the spfile. This is simple, and fairly fast, but unnecessary if the database is running.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The better way, if the database is running, is to select the parameter you want to view from the oracle view v$spparameter with a command like this:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SELECT value FROM v$spparameter WHERE name='processes';&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If you try to view the spfile with a text editor it may seem like it is plain text, but beware! The spfile will not behave correctly (if it works at all) if it has been edited by a text editor.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;How can I update values in my spfile?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The values in spfile are updated with the ALTER SYSTEM command, but to update the spfile we add an additional parameter of SCOPE.&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;ALTER SYSTEM SET processes=50 SCOPE=spfile;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;This command would update the parameter processes in the spfile. Since this parameter can only be set at startup, we say SCOPE=spfile and the change will be reflected when the database is restarted. Other options for SCOPE are memory which only changes the parameter until the database is restarted, and both which changes the instance immediately and will remain in effect after the database is restarted.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;How can I update values in my spfile when my database won’t start?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;So your database won’t startup because of a problem in your spfile. You can’t edit it with a text editor and you can’t use ALTER SYSTEM because your database is not running. It sounds like a problem, but really isn’t. Here’s what you do:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Connect up to your database as sysdba. You should get the message Connected to an idle instance&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Run the command CREATE pfile FROM spfile; specifying the location as above if necessary. You should now have a fresh version of the spfile.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Edit the pfile to update the parameter you need to update.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Run the command CREATE spfile FROM pfile; to move the changes you have just made back into the spfile.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Startup the database normally. It should read the changed spfile and start up correctly. You can optionally delete the pfile if you are done.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;a href="www.lifeaftercoffee.com/2005/09/29/oracle-pfile-and-spfile-for-parameters"&gt;www.lifeaftercoffee.com/2005/09/29/oracle-pfile-and-spfile-for-parameters&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115497889116781729?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115497889116781729'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115497889116781729'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/oracle-pfile-and-spfile.html' title='Oracle PFile and SPFile'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115489534454663172</id><published>2006-08-06T13:13:00.000-07:00</published><updated>2006-08-06T13:15:44.700-07:00</updated><title type='text'>Suspending and Resuming a Database</title><content type='html'>&lt;span style="font-family: verdana;"&gt;The ALTER SYSTEM SUSPEND statement suspends a database by halting all input and output (I/O) to datafiles (file header and file data) and control files, thus allowing a database to be backed up without I/O interference. When the database is suspended all preexisting I/O operations are allowed to complete and any new database accesses are placed in a queued state.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The suspend command suspends the database, and is not specific to an instance. Therefore, in an Oracle Real Application Clusters environment, if the suspend command is entered on one system, then internal locking mechanisms will propagate the halt request across instances, thereby quiescing all active instances in a given cluster. However, do not start a new instance while you suspend another instance, since the new instance will not be suspended.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Use the ALTER SYSTEM RESUME statement to resume normal database operations. You can specify the SUSPEND and RESUME from different instances. For example, if instances 1, 2, and 3 are running, and you issue an ALTER SYSTEM SUSPEND statement from instance 1, then you can issue a RESUME from instance 1, 2, or 3 with the same effect.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The suspend/resume feature is useful in systems that allow you to mirror a disk or file and then split the mirror, providing an alternative backup and restore solution. If you use a system that is unable to split a mirrored disk from an existing database while writes are occurring, then you can use the suspend/resume feature to facilitate the split.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The suspend/resume feature is not a suitable substitute for normal shutdown operations, however, since copies of a suspended database can contain uncommitted updates.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;br /&gt;Caution:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Do not use the ALTER SYSTEM SUSPEND statement as a substitute for placing a tablespace in hot backup mode. Precede any database suspend operation by an ALTER TABLESPACE BEGIN BACKUP statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The following statements illustrate ALTER SYSTEM SUSPEND/RESUME usage. The V$INSTANCE view is queried to confirm database status.&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SQL&gt; ALTER SYSTEM SUSPEND;&lt;br /&gt;System altered&lt;br /&gt;SQL&gt; SELECT DATABASE_STATUS FROM V$INSTANCE;&lt;br /&gt;DATABASE_STATUS&lt;br /&gt;---------&lt;br /&gt;SUSPENDED&lt;br /&gt;&lt;br /&gt;SQL&gt; ALTER SYSTEM RESUME;&lt;br /&gt;System altered&lt;br /&gt;SQL&gt; SELECT DATABASE_STATUS FROM V$INSTANCE;&lt;br /&gt;DATABASE_STATUS&lt;br /&gt;---------&lt;br /&gt;ACTIVE&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;a href="http://www.utexas.edu/its/unix/reference/oracledocs/v92/B10501_01/server.920/a96521/start.htm#9497"&gt;http://www.utexas.edu/its/unix/reference/oracledocs/v92/B10501_01/server.920/a96521/start.htm#9497&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115489534454663172?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489534454663172'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489534454663172'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/suspending-and-resuming-database.html' title='Suspending and Resuming a Database'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115489485344284010</id><published>2006-08-06T13:05:00.000-07:00</published><updated>2006-08-06T13:10:14.123-07:00</updated><title type='text'>Quiescing a Database</title><content type='html'>&lt;span style="font-family:verdana;"&gt;There are times when there is a need to put a database into a state where only DBA transactions, queries, fetches, or PL/SQL statements are allowed. This is called a quiesced state, in the sense that there are no ongoing non-DBA transactions, queries, fetches, or PL/SQL statements in the system. This quiesced state allows you or other administrators to perform actions that cannot safely be done otherwise. These actions are categorized as follows:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * Actions that can fail if concurrent user transactions access the same object. For example, changing the schema of a database table or adding a column to an existing table where a no-wait lock is required.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * Actions whose undesirable intermediate effect can be seen by concurrent user transactions. For example, a multistep procedure for reorganizing a table where the table is first exported, then dropped, and finally imported. A concurrent user who attempted to access the table after it was dropped, but before import, would see disturbing results.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Without the ability to quiesce the database, you would be required to shut down the database and reopen it in restricted mode. This is a serious restriction, especially for systems requiring 24 x 7 availability. Quiescing a database is much less of a restriction because it eliminates the disruption to users and downtime associated with shutting down and restarting the database.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Note:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;For this release of Oracle9i, in the quiesce database context a DBA is defined as user SYS or SYSTEM. Other users, including those with the DBA role are not allowed to issue the ALTER SYSTEM QUIESCE DATABASE statement or proceed after the database is quiesced.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Placing a Database into a Quiesced State&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;To place a database into a quiesced state, issue the following statement:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;ALTER SYSTEM QUIESCE RESTRICTED;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Any non-DBA active sessions will proceed until they become inactive. An active session is defined as a session that is currently inside of a transaction, a query, a fetch, or a PL/SQL statement; or a session that is currently holding any shared resources (for example, enqueues). No inactive sessions are allowed to become active. If a user, for example, issues a SQL query in an attempt to force an inactive session to become active, the query will appear to be hung. When the database is later unquiesced, the session is resumed, and the blocked action (for example, the previously mentioned SQL query) will be processed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Once all non-DBA sessions become inactive, the ALTER SYSTEM QUIESCE RESTRICTED statement finishes, and the database is considered as in a quiesced state. In an Oracle Real Application Clusters environment, this statement affects all instances, not just the one that issues the statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The database remains in the quiesced state even if the session that issued the statement exits. A DBA must log in to the database to issue the statement that specifically unquiesces the database.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;While in the quiesced state, you cannot use file system copy to backup the database's datafiles as cold backups, even if you do a checkpoint on every instance. The reason for this is that in the quiesced state the file headers of online datafiles continue to look like they are being accessed. They do not look the same as if a clean shutdown were done. Similarly, to perform a hot backup of the datafiles of any online tablespace while the database is in a quiesced state, you are still required to first place the tablespace into backup mode using the ALTER TABLESPACE... BEGIN BACKUP statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Restoring the System to Normal Operation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The following statement restores the database to normal operation:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;ALTER SYSTEM UNQUIESCE;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;All non-DBA activity is allowed to proceed. In an Oracle Real Application Clusters environment, this statement is not required to be issued from the same session, or even the same instance, as that which imposed the quiesce state. If the session issuing the ALTER SYSTEM UNQUIESCE statement should terminate abnormally, the Oracle database server ensures that the unquiesce operation finishes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Viewing the Quiesce State of an Instance&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The V$INSTANCE view can be queried to see the current state of an instance. It contains a column named ACTIVE_STATE, whose values are shown in the following table:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;ACTIVE_STATE |  Description&lt;br /&gt;-------------+------------------------------------&lt;br /&gt;NORMAL       |  Normal unquiesced state&lt;br /&gt;QUIESCING    |  Being quiesced, but there are still&lt;br /&gt;             |  active non-DBA sessions running&lt;br /&gt;QUIESCED     |  Quiesced, no active non-DBA sessions&lt;br /&gt;             |  are active or allowed&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Source: &lt;a href="http://www.utexas.edu/its/unix/reference/oracledocs/v92/B10501_01/server.920/a96521/start.htm#9497"&gt;http://www.utexas.edu/its/unix/reference/oracledocs/v92/B10501_01/server.920/a96521/start.htm#9497&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115489485344284010?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489485344284010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489485344284010'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/quiescing-database.html' title='Quiescing a Database'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115489431548752422</id><published>2006-08-06T12:56:00.000-07:00</published><updated>2006-08-06T12:58:35.633-07:00</updated><title type='text'>Startup and Shutdown Options</title><content type='html'>&lt;span style="font-family: verdana;"&gt;StartUp&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Starting up the instance with the NOMOUNT option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Starting the instance with the MOUNT option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Starting up the instance with the FORCE option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Starting the instance with the OPEN option&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;ShutDown&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Shutting down the database with the TRANSACTIONAL option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Shutting down the database with the IMMEDIATE option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Shutting down the database with the NORMAL option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Shutting down the database with the ABORT option&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Options&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the IMMEDIATE option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the NOMOUNT option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the NORMAL option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the MOUNT option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the TRANSACTIONAL option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the OPEN option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the FORCE option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the READ ONLY mode&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the ABORT option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Using the BACKGROUND_DUMP_DEST parameter&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Commands&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SHUTDOWN IMMEDIATE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SHUTDOWN NORMAL&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SHUTDOWN TRANSACTIONAL&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SHUTDOWN ABORT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;STARTUP OPEN READ ONLY FILE=init.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;STARTUP NOMOUNT PFILE=init.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;STARTUP MOUNT PFILE=init.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;STARTUP OPEN PFILE=init.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;STARTUP FORCE PFILE=init.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;ALTER DATABASE MOUNT;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;ALTER DATABASE OPEN;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SHUTDOWN IMMEDIATE&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;Exercise&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;connect system/manager@school as sysdba&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;startup&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SET linesize 1000 pagesize 55&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;COL name FORMAT a50&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;col parameter format a40&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;col username format a10&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;pause&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;--Start&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;CLEAR SCR&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- In this exercise you will learn how to START and SHUTDOWN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- the ORACLE database.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- Connect to SQL*Plus as the system/manager user.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;pause&lt;/span&gt;&lt;br /&gt;CONNECT system/manager@school AS SYSDBA&lt;br /&gt;pause&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Shutdown the database with the IMMEDIATE option and then&lt;br /&gt;-- start the instance with the NOMOUNT option.&lt;br /&gt;&lt;br /&gt;-- The IMMEDIATE option means not to wait for a user&lt;br /&gt;-- to log off and roll back uncommitted transactions, then&lt;br /&gt;-- shut down the instance and close the database.&lt;br /&gt;&lt;br /&gt;-- The NOMOUNT option starts the instance without mounting&lt;br /&gt;-- the database. It means that all of the memory structure&lt;br /&gt;-- and background processes are in place, but no database is&lt;br /&gt;-- attached to the instance.&lt;br /&gt;pause&lt;br /&gt;-- &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Shutdown&lt;br /&gt;SHUTDOWN IMMEDIATE&lt;br /&gt;CONNECT system/manager@school AS SYSDBA&lt;br /&gt;&lt;br /&gt;-- &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Startup&lt;br /&gt;STARTUP NOMOUNT PFILE=%ORACLE_BASE%\admin\school\pfile\init.ora&lt;br /&gt;pause&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Now, mount the database and then open it.&lt;br /&gt;&lt;br /&gt;-- Don't forget to check your alert file. The alert log file&lt;br /&gt;-- stores information that is extremely useful in order to know&lt;br /&gt;-- the health of the database. It records the starting and&lt;br /&gt;-- stopping of the databases, creation of new redo log files,&lt;br /&gt;-- datafiles, tablespaces, and most importantly, the Oracle&lt;br /&gt;-- system error messages. It is located in the BACKGROUND_DUMP_DEST&lt;br /&gt;-- parameter.&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ALTER DATABASE MOUNT;&lt;br /&gt;&lt;br /&gt;ALTER DATABASE OPEN;&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Shutdown the database with the NORMAL option and then&lt;br /&gt;-- start the instance with the MOUNT option.&lt;br /&gt;&lt;br /&gt;-- The NORMAL option will wait for users to log out and then, it&lt;br /&gt;-- will close the database and shutdown the instance.&lt;br /&gt;&lt;br /&gt;-- The MOUNT option, starts the instance, reads the control file,&lt;br /&gt;-- and attaches the database, but does not open it.&lt;br /&gt;pause&lt;br /&gt;-- &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Shutdown&lt;br /&gt;SHUTDOWN NORMAL&lt;br /&gt;CONNECT system/manager@school AS SYSDBA&lt;br /&gt;&lt;br /&gt;-- &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Startup&lt;br /&gt;STARTUP MOUNT PFILE=%ORACLE_BASE%\admin\school\pfile\init.ora&lt;br /&gt;pause&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Now, open the database.&lt;br /&gt;&lt;br /&gt;-- We must open the database since in the STARTUP command,&lt;br /&gt;-- we used the MOUNT option.&lt;br /&gt;&lt;br /&gt;-- Notice that the MOUNT option starts the instance, reads&lt;br /&gt;-- the control file, and attaches the database, but does not&lt;br /&gt;-- open it.&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ALTER DATABASE OPEN;&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Shutdown the database with the TRANSACTIONAL option and then&lt;br /&gt;-- start the instance and open the database.&lt;br /&gt;&lt;br /&gt;-- The TRANSACTIONAL option tells oracle not to wait for a user to&lt;br /&gt;-- log off, but wait for the client to end the transaction that is&lt;br /&gt;-- in progress, then shut down the instance and close the database.&lt;br /&gt;&lt;br /&gt;-- The OPEN option starts the instance, reads the control file,&lt;br /&gt;-- attaches the database, and then opens it. Notice that the OPEN&lt;br /&gt;-- option is a default option.&lt;br /&gt;-- You do not need to use the OPEN option, since it is the default&lt;br /&gt;-- option.&lt;br /&gt;pause&lt;br /&gt;-- &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Shutdown&lt;br /&gt;SHUTDOWN TRANSACTIONAL&lt;br /&gt;CONNECT system/manager@school AS SYSDBA&lt;br /&gt;&lt;br /&gt;-- &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Startup&lt;br /&gt;STARTUP OPEN PFILE=%ORACLE_BASE%\admin\school\pfile\init.ora&lt;br /&gt;pause&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Use the FORCE option to shutdown and then startup the database.&lt;br /&gt;-- This should be your last resort when you cannot shutdown&lt;br /&gt;-- your database.&lt;br /&gt;&lt;br /&gt;-- Make sure that you have already patiently waited for the&lt;br /&gt;-- database to be shutdown.&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;&lt;br /&gt;-- &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Shutdown and Startup&lt;br /&gt;STARTUP FORCE PFILE=%ORACLE_BASE%\admin\school\pfile\init.ora&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- You can also open your database on the READ ONLY mode.&lt;br /&gt;&lt;br /&gt;-- In the READ ONLY mode, you cannot insert, update, or&lt;br /&gt;-- delete any records.&lt;br /&gt;&lt;br /&gt;-- Nor are you allowed to create, alter, or drop any tables.&lt;br /&gt;&lt;br /&gt;-- Also, you can't change the structure of the database by adding&lt;br /&gt;-- tablespaces or datafiles.&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;&lt;br /&gt;SHUTDOWN IMMEDIATE&lt;br /&gt;CONNECT system/manager@school AS SYSDBA&lt;br /&gt;&lt;br /&gt;-- &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Startup&lt;br /&gt;STARTUP OPEN READ ONLY PFILE=%ORACLE_BASE%\admin\school\pfile\init.ora&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Now, let's connect to SQL*Plus as myuser.&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;CONNECT myuser/schooling@school&lt;br /&gt;pause&lt;br /&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Query the department table&lt;br /&gt;pause&lt;br /&gt;SELECT * FROM dept&lt;br /&gt;/&lt;br /&gt;pause&lt;br /&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Insert a record into the department table.&lt;br /&gt;pause&lt;br /&gt;INSERT INTO dept VALUES (50, 'EDUCATION','VIRGINIA')&lt;br /&gt;/&lt;br /&gt;-- Notice that you are not able to insert any record.&lt;br /&gt;pause&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLEAR SCR&lt;br /&gt;-- Shutdown the database with the ABORT option.&lt;br /&gt;-- The ABORT option tells Oracle not to wait for a user and do not&lt;br /&gt;-- roll back for any transaction and shutdown the instance.&lt;br /&gt;&lt;br /&gt;pause&lt;br /&gt;&lt;br /&gt;CONNECT system/manager@school AS sysdba&lt;br /&gt;&lt;br /&gt;-- &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Shutdown&lt;br /&gt;SHUTDOWN ABORT&lt;br /&gt;pause&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;a href="http://www.iselfschooling.com/mcfd1cd1/iscddbh02plm.htm"&gt;http://www.iselfschooling.com/mcfd1cd1/iscddbh02plm.htm&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115489431548752422?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489431548752422'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489431548752422'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/startup-and-shutdown-options.html' title='Startup and Shutdown Options'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115489411999651296</id><published>2006-08-06T12:52:00.000-07:00</published><updated>2006-08-06T12:55:20.230-07:00</updated><title type='text'>Oracle Startup and Shutdown</title><content type='html'>&lt;span style="font-family: verdana;"&gt;The best way to understand how all the diffrent files work together is to examine the Oracle startup proccess.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;When Oracle starts an instance it reads the spfile or pfile to determine the initialization paramters. It uses these paramters to allocate the SGA and create background proccesses. All this is done without associating a database to the instance! At this point the instance is started but not mounted, or as some say "Started in no mount mode". They say that because you can reach this state by using the SQL*Plus command "startup nomount".&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SQL&gt; startup nomount;&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  184549376 bytes&lt;br /&gt;Fixed Size                  1300928 bytes&lt;br /&gt;Variable Size             157820480 bytes&lt;br /&gt;Database Buffers           25165824 bytes&lt;br /&gt;Redo Buffers                 262144 bytes&lt;br /&gt;SQL&gt; quit&lt;br /&gt;# ps -ef | grep -i ora_&lt;br /&gt; oracle   720     1  0 14:14:20 ?        0:00 ora_reco_test&lt;br /&gt; oracle   710     1  0 14:14:19 ?        0:00 ora_mman_test&lt;br /&gt; oracle   708     1  0 14:14:19 ?        0:00 ora_pmon_test&lt;br /&gt; oracle   712     1  0 14:14:19 ?        0:00 ora_dbw0_test&lt;br /&gt; oracle   718     1  0 14:14:19 ?        0:00 ora_smon_test&lt;br /&gt; oracle   714     1  0 14:14:19 ?        0:00 ora_lgwr_test&lt;br /&gt; oracle   716     1  0 14:14:19 ?        0:00 ora_ckpt_test&lt;br /&gt; oracle   726     1  0 14:14:20 ?        0:00 ora_s000_test&lt;br /&gt; oracle   724     1  0 14:14:20 ?        0:00 ora_d000_test&lt;br /&gt; oracle   722     1  0 14:14:20 ?        0:00 ora_cjq0_test&lt;br /&gt;#&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;When a database is mounted, the datafiles are actually associated is the instance. It's somewhat akin to loading the bullets into a gun; the gun is mearly a vehicle to utilize bullets and without them it's utterly useless. As a fun test, you can rename the datafile directory (where the control and datafiles are) and startup the instance without mounting. You won't get an error, you won't get a complaint... because Oracle isn't interested in anything but the parameter files at this point. Even though the pfile specifies the location of the control file, it hasn't tried to open the control files yet so it won't complain!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;This last revolation is extremely important. Why? You'll notice that alot of the documenation, particularly reguarding recovery will tell you to connect to an instance even though it's in need of major recovery. At first glance, in some cases, you'll scratch your head trying to figure out why they expect you to start an instance of a database thats been destroyed. Well, now you know.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Moving along to the second phase of database startup, the database is mounted. In this step we associate the control, data, redo, and other database related files to the running instance. If you are missing files this is where you'll get your error. If you started your instance using nomount you can't use the startup command again, but you can use alter database statements to change the state of your instance.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Lets quickly look at what happens when you mount your database with the instance already running but with the all the data and control files missing (renamed data directory):&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SQL&gt; alter database mount;&lt;br /&gt;alter database mount&lt;br /&gt;*&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-00205: error in identifying controlfile, check alert log for more info&lt;br /&gt;SQL&gt; quit&lt;br /&gt;# tail /u01/app/oracle/admin/test/bdump/alert_test.log&lt;br /&gt;alter database mount&lt;br /&gt;Wed Oct 13 14:28:12 2004&lt;br /&gt;ORA-00202: controlfile: '/u02/oradata/test/control01.ctl'&lt;br /&gt;ORA-27037: unable to obtain file status&lt;br /&gt;SVR4 Error: 2: No such file or directory&lt;br /&gt;Additional information: 3&lt;br /&gt;Wed Oct 13 14:28:12 2004&lt;br /&gt;Controlfile identified with block size 0&lt;br /&gt;Wed Oct 13 14:28:12 2004&lt;br /&gt;ORA-205 signalled during: alter database mount...&lt;br /&gt;#&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Notice that it complains about the first controlfile and not the datafiles. Thats because the parameter file has a listing of all the controlfiles and the controlfile is responsable for storing information about all the other datafiles and resources used by the database. If the controlfile can't be read the database doesn't know what else exists! This is why you should be careful to keep good backups of your controlfiles using plain ol' system backups. This is also why Oracle maintains multiple copies (typically 3) of the control file for safety.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Lets put all the datafiles back and try mounting the database again.&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;# mv test.HOLD/ test&lt;br /&gt;# sqlplus sys/passwd as sysdba&lt;br /&gt;SQL*Plus: Release 10.1.0.2.0 - Production on Wed Oct 13 14:36:09 2004&lt;br /&gt;Copyright (c) 1982, 2004, Oracle.  All rights reserved.&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production&lt;br /&gt;With the Partitioning, OLAP and Data Mining options&lt;br /&gt;&lt;br /&gt;SQL&gt; alter database mount;&lt;br /&gt;Database altered.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Looking at the proccesses on the system, you'll notice that after mounting the database no change has occured to the proccesses.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Once an instance is started using a pfile and the mount proccess has used the controlfile(s) to associate the datafiles with the instance we need to open the database. Untill a database is opened it is not accessable. It's equivilent to starting a system in single-user mode. Some ammount of interaction with the databse is avalible at this stage but it's limited to fixed tables and views. The fixed tables and views are those in the data dictionary (Oracle's internal configuration tables).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;But here's the confusing part, the normal data dictionary tables (ALL_USERS, for example) will give you an error, but most of the V$ tables, which are supposed to be the dynamic tables, work fine! What exactly "fixed" is supposed to mean in the case I dunno.&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SQL&gt; select * from all_users;&lt;br /&gt;select * from all_users&lt;br /&gt;             *&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-01219: database not open: queries allowed on fixed&lt;br /&gt;tables/views only&lt;br /&gt;SQL&gt; select status from v$instance;&lt;br /&gt;&lt;br /&gt;STATUS&lt;br /&gt;------------&lt;br /&gt;MOUNTED&lt;br /&gt;SQL&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;To open the database for normal access, we can alter the database again.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; alter database open;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Database altered.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The shutdown proccess is the simply opposite of the startup.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; shutdown immediate;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Database closed.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Database dismounted.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;ORACLE instance shut down.&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://cuddletech.com/articles/oracle/node31.html"&gt;http://cuddletech.com/articles/oracle/node31.html&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115489411999651296?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489411999651296'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489411999651296'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/oracle-startup-and-shutdown.html' title='Oracle Startup and Shutdown'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115489193051468359</id><published>2006-08-06T12:13:00.000-07:00</published><updated>2006-08-06T12:20:47.833-07:00</updated><title type='text'>Oracle Managed Files (OMF)</title><content type='html'>&lt;span style="font-family:verdana;"&gt;OMF simplifies the creation of databases as Oracle does all OS operations and file naming. It has several advantages including:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * Automatic cleanup of the filesystem when database objects are dropped.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * Standardized naming of database files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * Increased portability since file specifications are not needed.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * Simplified creation of test systems on differing operating systems.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * No unused files wasting disk space.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;OMF Parameters&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: courier new;font-family:verdana;" &gt;1. DB_CREATE_FILE_DEST&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Defines the location of the default file system directory where Oracle creates datafiles or tempfiles when no file specification is given in the creation operation. Also used as the default file system directory for online redo log and control files if DB_CREATE_ONLINE_LOG_DEST_n is not specified.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: courier new;font-family:verdana;" &gt;2. DB_CREATE_ONLINE_LOG_DEST_n&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Defines the location of the default file system directory for online redo log files and control file creation when no file specification is given in the creation operation. You can use this initialization parameter multiple times, where n specifies a multiplexed copy of the online redo log or control file. You can specify up to five multiplexed copies.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The location of database files is defined using the DB_CREATE_FILE_DEST parameter. If it is defined on its own all files are placed in the same location. All files will be created with unique names, 100 MB in size, with properties AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED. If the DB_CREATE_ONLINE_LOG_DEST_n parameter is defined alternate locations and levels of multiplexing can be defined for Logfiles. These parameters are dymanic and can be changed using the ALTER SYSTEM statement:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;  ALTER SYSTEM SET DB_CREATE_FILE_DEST='C:\Oracle\Oradata\TSH1';&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Files typically have a default size of 100M and are named using the following formats &lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;File Type  Format&lt;br /&gt;Controlfiles  ora_%u.ctl&lt;br /&gt;Redo Log Files  ora_%g_%u.log&lt;br /&gt;Datafiles  ora_%t_%u.dbf&lt;br /&gt;Temporary Datafiles  ora_%t_%u.tmp&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  u% is a unique 8 digit code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  g% is the logfile group number&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  %t is the tablespace name&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Do not rename an Oracle-managed file. Oracle identifies an Oracle-managed file based on its name. If you rename the file, Oracle is no longer able to recognize it as an Oracle-managed file and will not manage the file accordingly.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Managing Controlfiles Using OMF&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;During database creation the controlfile names are not specified. Instead, a controlfile is created for each DB_CREATE_ONLINE_LOG_DEST_n specified in the init.ora file. Once the database creation is complete the CONTROL_FILES parameter can be set in the init.ora file using the generated names shown in the V$CONTROLFILE view.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Managing Redo Log Files Using OMF&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;When using OMF for redo logs the DB_CREATE_ONLINE_LOG_DEST_n parameters in the init.ora file decide on the locations and numbers of logfile members. For exmple:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;  DB_CREATE_ONLINE_LOG_DEST_1 = c:\Oracle\Oradata\TSH1&lt;br /&gt;  DB_CREATE_ONLINE_LOG_DEST_2 = d:\Oracle\Oradata\TSH1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The above parameters mean two members will be created for the logfile group in the specified locations when the ALTER DATABASE ADD LOGFILE; statement is issued. Oracle will name the file and increment the group number if they are not specified.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The ALTER DATABASE DROP LOGFILE GROUP 3; statement will remove the group and it members from the database and delete the files at operating system level.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Managing Tablespaces Using OMF&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;As shown previously the DB_CREATE_FILE_DEST parameter in the init.ora file specifies the location of the datafiles for OMF tablespaces. Since the file location is specified and Oracle will name the file, new tablespaces can be created using the following statement:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    CREATE TABLESPACE tsh_data;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The resultant datafiles will have a default size of 100M and AUTOEXTEND UNLIMITED. For a specific size file use:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    CREATE TABLESPACE tsh_data DATAFILE SIZE 150M;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;To add a datafile to a tablespace use:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    ALTER TABLESPACE tsh_data ADD DATAFILE;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If a tablespace is dropped, Oracle will remove the OS files also. For tablespaces not using the OMF feature this cleanup can be performed by issuing the statement:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    DROP TABLESPACE tsh_data INCLUDING CONTENTS AND DATAFILES;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Default Temporary Tablespace&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;In previous releases, if you forgot to assign a temporary tablespace to a user the SYSTEM tablespace was used. This can cause contention and is considered bad practice. To prevent this 9i gives you the ability to assign a default temporary tablespace. If a temporary tablespace is not explicitly assigned the user is assigned to this tablespace.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A default temporary tablespace can be created during database creation or assigned afterwards:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;  CREATE DATABASE TSH1&lt;br /&gt;  ....&lt;br /&gt;  DEFAULT TEMPORARY TABLESPACE dts1&lt;br /&gt;  TEMPFILE 'c:\Oracle\Oradata\dts_1.f' SIZE 20M&lt;br /&gt;  EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;&lt;br /&gt;&lt;br /&gt;  -- or&lt;br /&gt;&lt;br /&gt;  ALTER DATABASE DEFAULT TEMPORARY TABLESPACE dts2;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A default temporary tablespace cannot be taken offline until a new default temporary tablespace is brought online.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Source&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96521/omf.htm"&gt;&lt;span style="font-family:verdana;"&gt;http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96521/omf.htm&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.oracle-base.com/articles/9i/OracleManagedFiles.php"&gt;&lt;span style="font-family:verdana;"&gt;http://www.oracle-base.com/articles/9i/OracleManagedFiles.php&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Also See&lt;/span&gt;&lt;br /&gt;&lt;a href="http://orafaq.com/node/6"&gt;&lt;span style="font-family:verdana;"&gt;http://orafaq.com/node/6&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115489193051468359?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489193051468359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115489193051468359'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/oracle-managed-files-omf.html' title='Oracle Managed Files (OMF)'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115459519226491772</id><published>2006-08-03T01:49:00.000-07:00</published><updated>2006-08-03T01:55:38.983-07:00</updated><title type='text'>Soft and Hard Parses</title><content type='html'>SQL statement is submitted to oracle =&gt; Oracle checks if statement has already been processed and if the resultant parse information still exists in the library cache. &lt;br /&gt;&lt;br /&gt;If Yes =&gt; Parse Activity need not be repeated (this is a soft parse)&lt;br /&gt;If No  =&gt; Generate Parse information from scratch (this is a hard parse)&lt;br /&gt;&lt;br /&gt;NOTE: "ALTER system FLUSH shared_pool" will force all subsequent SQL statements to hard parse the next time that they are run.&lt;br /&gt;&lt;br /&gt;Examples of soft and hard parse&lt;br /&gt;-------------------------------&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;   1. ALTER SESSION SET sql_trace=true;&lt;br /&gt;   2. SELECT * FROM dual WHERE 1=1; -- Hard Parse&lt;br /&gt;   3. SELECT /* Some Comment */ * FROM dual WHERE 1=1; -- Hard Parse&lt;br /&gt;   4. SELECT * FROM dual WHERE 1=1; -- Soft Parse&lt;br /&gt;   5. ALTER system FLUSH shared_pool;&lt;br /&gt;   6. SELECT * FROM dual WHERE 1=1; -- Hard Parse&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;NOTE: Note that Step 3 is different from Steps 2,4 and 6. Even though the only difference is a comment (/* Some Comment */) that makes no difference to the data set returned or to the chosen access path, the statement is still treated as a different statement by Oracle.&lt;br /&gt;&lt;br /&gt;These steps generate SQL_TRACE output as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Step 1: ALTER SESSION SET sql_trace=true;&lt;br /&gt;Sets up the tracing.&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Step 2: select * from dual where 1=1&lt;br /&gt;&lt;br /&gt;PARSING IN CURSOR #1 len=28 dep=0 uid=65 oct=3 lid=65 tim=1127532894840234 hv=1584415464 ad='583962ac'&lt;br /&gt;select * from dual where 1=1&lt;br /&gt;END OF STMT&lt;br /&gt;PARSE #1:c=0,e=3962,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=1127532894840222&lt;br /&gt;EXEC #1:c=0,e=52,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=1127532894840843&lt;br /&gt;FETCH #1:c=0,e=265,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=1,tim=1127532894841178&lt;br /&gt;FETCH #1:c=0,e=3,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=1127532894882236&lt;br /&gt;STAT #1 id=1 cnt=1 pid=0 pos=1 obj=195 op='TABLE ACCESS FULL DUAL (cr=3 pr=0 pw=0 time=254 us)'&lt;br /&gt;&lt;br /&gt;'PARSE #1' - indicates that there has been a parse call for this statement&lt;br /&gt;'mis=1'    - indicates that this is a hard parse&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Step 3: select /* Some Comment */ * from dual where 1=1;&lt;br /&gt;&lt;br /&gt;PARSING IN CURSOR #2 len=47 dep=0 uid=65 oct=3 lid=65 tim=1127532904993772 hv=3208276547 ad='568f76bc'&lt;br /&gt;select /* Some Comment */ * from dual where 1=1&lt;br /&gt;END OF STMT&lt;br /&gt;PARSE #2:c=0,e=1490,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=1127532904993761&lt;br /&gt;EXEC #2:c=0,e=39,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=1127532904993919&lt;br /&gt;FETCH #2:c=0,e=93,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=1,tim=1127532904994083&lt;br /&gt;FETCH #2:c=0,e=3,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=1127532905034634&lt;br /&gt;STAT #2 id=1 cnt=1 pid=0 pos=1 obj=195 op='TABLE ACCESS FULL DUAL (cr=3 pr=0 pw=0 time=82 us)'&lt;br /&gt;&lt;br /&gt;'hard' parse (mis=1) since this SQL has not been parsed before. (although only a comment was added)&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Step 4: select * from dual where 1=1;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PARSING IN CURSOR #1 len=28 dep=0 uid=65 oct=3 lid=65 tim=1127532927402693 hv=1584415464 ad='583962ac'&lt;br /&gt;select * from dual where 1=1&lt;br /&gt;END OF STMT&lt;br /&gt;PARSE #1:c=0,e=112,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=1127532927402682&lt;br /&gt;EXEC #1:c=0,e=42,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=1127532927402838&lt;br /&gt;FETCH #1:c=0,e=75,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=1,tim=1127532927402983&lt;br /&gt;FETCH #1:c=0,e=3,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=1127532927443401&lt;br /&gt;STAT #1 id=1 cnt=1 pid=0 pos=1 obj=195 op='TABLE ACCESS FULL DUAL (cr=3 pr=0 pw=0 time=63 us)'&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;br /&gt;Since this select is a repeat of Step 2 it has already been parsed and, in this case, the parse information is still in the library cache, the query is found in the shared pool and a soft parse occurs. The parse line shows this as mis=0.&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Step 5: ALTER system FLUSH shared_pool;&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;This step 'removes' all the SQL in the shared pool&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Step 6: select * from dual where 1=1;&lt;br /&gt;&lt;br /&gt;PARSING IN CURSOR #2 len=28 dep=0 uid=65 oct=3 lid=65 tim=1127533057421354 hv=1584415464 ad='583962ac'&lt;br /&gt;select * from dual where 1=1&lt;br /&gt;END OF STMT&lt;br /&gt;PARSE #2:c=10000,e=3360,p=0,cr=4,cu=0,mis=1,r=0,dep=0,og=1,tim=1127533057421344&lt;br /&gt;EXEC #2:c=0,e=30,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=1127533057421494&lt;br /&gt;FETCH #2:c=0,e=177,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=1,tim=1127533057421744&lt;br /&gt;FETCH #2:c=0,e=4,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=1127533057462246&lt;br /&gt;STAT #2 id=1 cnt=1 pid=0 pos=1 obj=195 op='TABLE ACCESS FULL DUAL (cr=3 pr=0 pw=0 time=163 us)'&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;br /&gt;(The trace output above follows large amounts of recursive SQL that has also had to be reparsed due to flushing ALL SQL from the shared pool).&lt;br /&gt;The query in this step is the same as the query in Step 2 and Step 4 Step 2 was a hard parse whereas Step 4 was soft parsed. This time a hard parse is required since the SQL has been flushed from the shared pool and so the parse line shows 'mis=1'.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TKProf Output&lt;br /&gt;=============&lt;br /&gt;&lt;br /&gt;Steps 2, 4 and 6:&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;select *&lt;br /&gt;from&lt;br /&gt; dual where 1=1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;call     count       cpu    elapsed       disk      query    current        rows&lt;br /&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;br /&gt;Parse        3      0.00       0.00          0          0          0           0&lt;br /&gt;Execute      3      0.00       0.00          0          0          0           0&lt;br /&gt;Fetch        6      0.00       0.00          0          9          0           3&lt;br /&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;br /&gt;total       12      0.00       0.00          0          9          0           3&lt;br /&gt;&lt;br /&gt;Misses in library cache during parse: 2&lt;br /&gt;Optimizer mode: ALL_ROWS&lt;br /&gt;Parsing user id: 65&lt;br /&gt;&lt;br /&gt;Rows     Row Source Operation&lt;br /&gt;-------  ---------------------------------------------------&lt;br /&gt;      1  TABLE ACCESS FULL DUAL (cr=3 pr=0 pw=0 time=254 us)&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;br /&gt;Observation : The Parse count above shows 3 parse calls.&lt;br /&gt;This consists of two Hard Parses (Step 2 and Step 6) and a single soft parse (Step 4).&lt;br /&gt;'Misses in library cache during parse: 2' records where the SQL was not found (i.e. a library cache miss) in the library cache and indicates that 2 of the parses were hard parses. &lt;br /&gt;Step 4 found an existing entry in the library cache for this statement and therefore, only a soft parse was necessary.&lt;br /&gt;&lt;br /&gt;Step 3:&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;select /* Some Comment */ *&lt;br /&gt;from&lt;br /&gt; dual where 1=1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;call     count       cpu    elapsed       disk      query    current        rows&lt;br /&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;br /&gt;Parse        1      0.00       0.00          0          0          0           0&lt;br /&gt;Execute      1      0.00       0.00          0          0          0           0&lt;br /&gt;Fetch        2      0.00       0.00          0          3          0           1&lt;br /&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;br /&gt;total        4      0.00       0.00          0          3          0           1&lt;br /&gt;&lt;br /&gt;Misses in library cache during parse: 1&lt;br /&gt;Optimizer mode: ALL_ROWS&lt;br /&gt;Parsing user id: 65&lt;br /&gt;&lt;br /&gt;Rows     Row Source Operation&lt;br /&gt;-------  ---------------------------------------------------&lt;br /&gt;      1  TABLE ACCESS FULL DUAL (cr=3 pr=0 pw=0 time=82 us)&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;Observation : In this case the Query shows a hard parse as the parse count is 1 and the 'Misses in library cache during parse: 1'. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Source: After reading Note 34433.1, attitudenine was trying out what was said there and thats what produced the above output.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115459519226491772?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115459519226491772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115459519226491772'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/soft-and-hard-parses.html' title='Soft and Hard Parses'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115452948186958194</id><published>2006-08-02T07:36:00.000-07:00</published><updated>2006-08-02T07:38:02.276-07:00</updated><title type='text'>Check for which objects are being locked and by whom</title><content type='html'>&lt;pre class="code"&gt;&lt;br /&gt;&lt;br /&gt;select  nvl(S.USERNAME,'Internal') username,&lt;br /&gt;        nvl(S.TERMINAL,'None') terminal,&lt;br /&gt;        L.SID||','||S.SERIAL# Kill,&lt;br /&gt;        U1.NAME||'.'||substr(T1.NAME,1,20) tab,&lt;br /&gt;        decode(L.LMODE,1,'No Lock',&lt;br /&gt;                2,'Row Share',&lt;br /&gt;                3,'Row Exclusive',&lt;br /&gt;                4,'Share',&lt;br /&gt;                5,'Share Row Exclusive',&lt;br /&gt;                6,'Exclusive',null) lmode,&lt;br /&gt;        decode(L.REQUEST,1,'No Lock',&lt;br /&gt;                2,'Row Share',&lt;br /&gt;                3,'Row Exclusive',&lt;br /&gt;                4,'Share',&lt;br /&gt;                5,'Share Row Exclusive',&lt;br /&gt;                6,'Exclusive',null) request&lt;br /&gt;from    V$LOCK L,&lt;br /&gt;        V$SESSION S,&lt;br /&gt;        SYS.USER$ U1,&lt;br /&gt;        SYS.OBJ$ T1&lt;br /&gt;where   L.SID = S.SID&lt;br /&gt;and     T1.OBJ# = decode(L.ID2,0,L.ID1,L.ID2)&lt;br /&gt;and     U1.USER# = T1.OWNER#&lt;br /&gt;and     S.TYPE != 'BACKGROUND'&lt;br /&gt;order by 1,2,5&lt;br /&gt;&lt;br /&gt;&lt;/pre class="code"&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115452948186958194?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115452948186958194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115452948186958194'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/08/check-for-which-objects-are-being.html' title='Check for which objects are being locked and by whom'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115357872635883843</id><published>2006-07-22T07:30:00.000-07:00</published><updated>2006-07-22T07:32:06.736-07:00</updated><title type='text'>Sys_Context Function</title><content type='html'>&lt;span style="font-family:verdana;"&gt;The sys_context function can be used to retrieve information about the Oracle environment.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The syntax for the sys_context function is:&lt;/span&gt;&lt;pre class="code"&gt;&lt;br /&gt;      sys_context( namespace, parameter, [ length ] )&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;* namespace is an Oracle namespace that has already been created. If the namespace of 'USERENV' is used, attributes describing the current Oracle session can be returned.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;* parameter is a valid attribute that has been set using the DBMS_SESSION.set_context procedure.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;* length is optional. It is the length of the return value in bytes. If this parameter is omitted or if an invalid entry is provided, the sys_context function will default to 256 bytes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;USERENV is an Oracle provided namespace that describes the current session. Sample queries using parameters from the 'USERENV' namespace are listed below&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SELECT Sys_Context('USERENV', 'DB_DOMAIN') FROM dual&lt;br /&gt;-- us.acme.com&lt;br /&gt;SELECT Sys_Context('USERENV', 'DB_NAME')   FROM dual&lt;br /&gt;-- orcl&lt;br /&gt;SELECT Sys_Context('USERENV', 'HOST') FROM dual    &lt;br /&gt;-- pc-mydb&lt;br /&gt;SELECT Sys_Context('USERENV', 'INSTANCE') FROM dual&lt;br /&gt;-- 1&lt;br /&gt;SELECT Sys_Context('USERENV', 'INSTANCE_NAME') FROM dual&lt;br /&gt;-- orcl&lt;br /&gt;SELECT Sys_Context('USERENV', 'IP_ADDRESS') FROM dual&lt;br /&gt;-- 15x.xx.245.138&lt;br /&gt;SELECT Sys_Context('USERENV', 'TERMINAL') FROM dual &lt;br /&gt;-- pc-mydb&lt;br /&gt;SELECT Sys_Context('USERENV', 'SERVER_HOST') FROM dual&lt;br /&gt;-- ap601gns&lt;br /&gt;SELECT Sys_Context('USERENV', 'NLS_DATE_FORMAT') FROM dual&lt;br /&gt;-- DD-MON-RR&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;With Excerpts from:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.psoug.org/reference/sys_context.html"&gt;&lt;span style="font-family:verdana;"&gt;http://www.psoug.org/reference/sys_context.html&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/functions150.htm"&gt;&lt;span style="font-family:verdana;"&gt;http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/functions150.htm&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.techonthenet.com/oracle/functions/sys_context.php"&gt;&lt;span style="font-family:verdana;"&gt;http://www.techonthenet.com/oracle/functions/sys_context.php&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115357872635883843?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115357872635883843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115357872635883843'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/syscontext-function.html' title='Sys_Context Function'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115357314464230144</id><published>2006-07-22T05:56:00.000-07:00</published><updated>2006-07-22T06:00:51.853-07:00</updated><title type='text'>Userenv Function</title><content type='html'>&lt;span style="font-family: verdana;"&gt;In Oracle/PLSQL, the userenv function can be used to retrieve information about the current Oracle session. Although this function still exists in Oracle for backwards compatibility, it is recommended that you use the  sys_context function instead.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The syntax for the userenv function is:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;       userenv( parameter )&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;parameter is the value to return from the current Oracle session. The possible values are:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;CLIENT_INFO   Returns user session information stored using &lt;br /&gt;                          the DBMS_APPLICATION_INFO package&lt;br /&gt;ENTRYID       Available auditing entry identifier&lt;br /&gt;INSTANCE      The identifier number of the current instance&lt;br /&gt;ISDBA         Returns TRUE if the user has DBA privileges. &lt;br /&gt;                          Otherwise, it will return FALSE.&lt;br /&gt;LANG          The ISO abbreviation for the language&lt;br /&gt;LANGUAGE      The language, territory, and character of &lt;br /&gt;                      the session in the following format:&lt;br /&gt;                          Language_Territory.Characterset&lt;br /&gt;SESSIONID     The identifier of the auditing session&lt;br /&gt;TERMINAL      The OS identifier of the current session&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Sample Values from my PC&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SELECT UserEnv('CLIENT_INFO') FROM dual -- Returns NULL&lt;br /&gt;SELECT UserEnv('ENTRYID') FROM dual     -- 0&lt;br /&gt;SELECT UserEnv('INSTANCE') FROM dual    -- 1&lt;br /&gt;SELECT UserEnv('ISDBA') FROM dual       -- FALSE&lt;br /&gt;SELECT UserEnv('LANG') FROM dual        -- US&lt;br /&gt;SELECT UserEnv('LANGUAGE') FROM dual    -- AMERICAN_AMERICA.UTF8&lt;br /&gt;SELECT UserEnv('SESSIONID') FROM dual   -- 7297876&lt;br /&gt;SELECT UserEnv('TERMINAL') FROM dual    -- pc-mydb&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;a href="http://www.techonthenet.com/oracle/functions/userenv.php"&gt;http://www.techonthenet.com/oracle/functions/userenv.php&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115357314464230144?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115357314464230144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115357314464230144'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/userenv-function.html' title='Userenv Function'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115356707997295047</id><published>2006-07-22T04:04:00.000-07:00</published><updated>2006-07-22T04:18:09.103-07:00</updated><title type='text'>Undo Management - Manual and Automatic</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Oracle Database keeps records of actions of transactiion, before they are committed and Oracle needs this information to rollback or Undo the Changes to the database. These records in Oracle are called &lt;span style="font-style: italic;"&gt;Rollback or Undo Records&lt;/span&gt;. These records are used to Rollback transactions when a rollback statement is issued or during recovery of a database or to provide a read consistent view of data.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Until Oracle 8i and also in 9i, Oracle uses Rollback Segments to manage the Undo Data. Starting with Oracle 9i, DBA's are provided with a new feature referred to as "Undo Tablespace" which allows the dba to exert more control on how long Undo information is retained and also eliminates the complexity of managing Rollback Segments in certain environments.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Starting with 9i, the &lt;span style="font-weight: bold; color: rgb(102, 102, 102);"&gt;rollback segment way is referred to as Manual Undo Management Mode&lt;/span&gt; and the new &lt;span style="font-weight: bold; color: rgb(102, 102, 102);"&gt;Undo Tablespaces method as the Automatic Undo Management Mode&lt;/span&gt;. Although both rollback Segments and Undo Tablespaces are supported in Oracle 9i, both modes cannot be used. System Rollback segment exists in both the modes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;&lt;u&gt;Init.ora Parameters for Automatic Undo Management&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;span style="font-weight: bold;"&gt;UNDO_MANAGEMENT&lt;/span&gt; : This parameter sets the mode in which oracle manages the Undo Information.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The default value for this parameter is MANUAL so that all your old init.ora files can be used without any changes. To set the database in an automated mode, set this value to AUTO. ( UNDO_MANAGEMENT = AUTO)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;span style="font-weight: bold;"&gt;UNDO_TABLESPACE&lt;/span&gt; : This parameter defines the tablespaces that are to be used as Undo Tablespaces. If no value is specified oracle grabs the first available Undo Tablespace or if there are none present, Oracle will use the system rollback segment to startup. This value is dynamic and can be changed online ( UNDO_TABLESPACE = undo_tbs1 )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;span style="font-weight: bold;"&gt;UNDO_RETENTION&lt;/span&gt; : This value specifies the amount of time, Undo is kept in the tablespace. This applies to both committed and uncommitted transactions since the introduction of FlashBack Query feature in Oracle needs this information to create a read consistent copy of the data in the past. Default value is 900 Secs ( UNDO_RETENTION = 500)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;span style="font-weight: bold;"&gt;UNDO_SUPRESS_ERRORS&lt;/span&gt; : This is a good thing to know about in case your code has the alter transaction commands that perform manual undo management operations. Set this to true to suppress the errors generated when manual management SQL operations are issued in an automated management mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;Creating and Managing Undo Tablespaces :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Undo tablespaces use syntax that is similar to regular tablespaces except that they use the keyword UNDO. These tablespaces can be created during the database creation time or can be added to an existing database using the create UNDO Tablespace command&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Create DATABASE mydb controlfile ...........&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;UNDO Tablespace undo_tbs0 datafile '/vol1/data/mydb/undotbs0.dbf' ...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Create UNDO Tablespace undo_tbs1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;datafile '/vol1/data/uday/undotbs1.dbf' size 25m autoextend on;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;All operations like Renaming a data file, Adding a datafile, Online /Offline Swith or Start Backup / End Backup Switch can be made using the regular alter tablespace command. All other operations are managed by Oracle in the automated management mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;Monitoring :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;span style="font-weight: bold;"&gt;v$UNDOSTAT&lt;/span&gt; : This view contains statistics for monitoring the effects of transaction execution on Undo Space in the current instance. These are available for space usage, transaction concurrency and length of query operations. This view contains information that spans over a 24 hour period and each row in this view contains data for a 10 minute interval specified by the BEGIN_TIME and END_TIME.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.dbasupport.com/oracle/ora9i/undo.shtml"&gt;http://www.dbasupport.com/oracle/ora9i/undo.shtml&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115356707997295047?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115356707997295047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115356707997295047'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/undo-management-manual-and-automatic.html' title='Undo Management - Manual and Automatic'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115298047313755911</id><published>2006-07-15T09:16:00.000-07:00</published><updated>2006-07-15T09:21:13.433-07:00</updated><title type='text'>Query to find locked objects</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Run the below query to check for locked objects&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SELECT DISTINCT session_id as "Session Id",&lt;br /&gt;       a.os_user_name as "Os user",&lt;br /&gt;       b.object_name "Object Name",&lt;br /&gt;       decode(a.locked_mode,&lt;br /&gt;              2 ,'ROW SHARE MODE',&lt;br /&gt;              3 ,'ROW EXCLUSIVE MODE',&lt;br /&gt;              4 ,'SHARE MODE',&lt;br /&gt;              5 ,'SHARE ROW EXCLUSIVE MODE',&lt;br /&gt;              6 ,'EXCLUSIVE','UNKNOWN')as "Lock Mode"&lt;br /&gt;from   v$locked_object a,&lt;br /&gt;       all_objects b&lt;br /&gt;WHERE  a.object_id = b.object_id&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Eg: The&lt;/span&gt; &lt;span style="font-family: courier new;"&gt;'SELECT ... FOR UPDATE'&lt;/span&gt; &lt;span style="font-family: verdana;"&gt;statement below will lock the EMP table. &lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SQL&gt; SELECT *&lt;br /&gt;     FROM   emp&lt;br /&gt;     WHERE  ename = 'xyz'&lt;br /&gt;     FOR UPDATE;&lt;br /&gt;&lt;/pre class="code"&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;After locking EMP table, run the lock-checker query&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;SQL&gt; /&lt;br /&gt;&lt;br /&gt;Session Id  Os user  Object Name  Lock Mode&lt;br /&gt;----------  -------  -----------  ------------------&lt;br /&gt;       681  myuser           EMP  ROW EXCLUSIVE MODE&lt;br /&gt;&lt;/pre class="code"&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115298047313755911?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115298047313755911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115298047313755911'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/query-to-find-locked-objects.html' title='Query to find locked objects'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115297443047310537</id><published>2006-07-15T07:40:00.000-07:00</published><updated>2006-07-28T23:39:15.496-07:00</updated><title type='text'>Reading an Explain Plan</title><content type='html'>&lt;span style="font-family:verdana;"&gt;We'll take a look at a query plan resulting from a query against the SCOTT/TIGER tables (note, I add primary keys to the EMP and DEPT tables - hence, they are indexed):&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;scott@ORA920&gt; delete from plan_table;&lt;br /&gt;7 rows deleted.&lt;br /&gt;&lt;br /&gt;scott@ORA920&gt; explain plan for&lt;br /&gt;2  select ename, dname, grade&lt;br /&gt;3    from emp, dept, salgrade&lt;br /&gt;4   where emp.deptno = dept.deptno&lt;br /&gt;5     and emp.sal between salgrade.losal and salgrade.hisal&lt;br /&gt;6  /&lt;br /&gt;Explained.&lt;br /&gt;&lt;br /&gt;scott@ORA920&gt; @?/rdbms/admin/utlxpls&lt;br /&gt;&lt;br /&gt;PLAN_TABLE_OUTPUT&lt;br /&gt;-----------------------------------------------------------------&lt;br /&gt;| Id  | Operation                    |Name     |Rows|Bytes|Cost |&lt;br /&gt;-----------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT             |         |    |     |     |&lt;br /&gt;|   1 |  NESTED LOOPS                |         |    |     |     |&lt;br /&gt;|   2 |   NESTED LOOPS               |         |    |     |     |&lt;br /&gt;|   3 |    TABLE ACCESS FULL         | SALGRADE|    |     |     |&lt;br /&gt;|*  4 |    TABLE ACCESS FULL         | EMP     |    |     |     |&lt;br /&gt;|   5 |   TABLE ACCESS BY INDEX ROWID| DEPT    |    |     |     |&lt;br /&gt;|*  6 |    INDEX UNIQUE SCAN         | DEPT_PK |    |     |     |&lt;br /&gt;-----------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;4 - filter("EMP"."SAL"&lt;="SALGRADE"."HISAL" AND            "EMP"."SAL"&gt;="SALGRADE"."LOSAL")&lt;br /&gt;6 - access("EMP"."DEPTNO"="DEPT"."DEPTNO")&lt;br /&gt;&lt;br /&gt;Note: rule based optimization&lt;br /&gt;&lt;br /&gt;21 rows selected.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Now - what happens first?  How does that plan actually get evaluated?  First I'll show you the psuedo code for how the plan is evaluated and then we'll discuss how I arrived at this conclusion:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;For salgrade in (select * from salgrade)&lt;br /&gt;Loop&lt;br /&gt;For emp in ( select * from emp )&lt;br /&gt;Loop&lt;br /&gt; If ( emp.sal between salgrade.losal and salgrade.hisal )&lt;br /&gt; Then&lt;br /&gt;     Select * into dept_rec&lt;br /&gt;       From dept&lt;br /&gt;      Where dept.deptno = emp.deptno;&lt;br /&gt;&lt;br /&gt;     OUTPUT RECORD with fields from salgrade,emp,dept&lt;br /&gt; End if;&lt;br /&gt;End loop;&lt;br /&gt;End loop;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The way I read the plan was to turn it into a graph of sorts - an evaluation tree.  In order to do that, we need to understand something about access paths.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;For detailed information on the access paths available to Oracle, please see the Oracle Performance and Tuning Guide.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;In order to build the tree - we can start at the top, with step 1.  That will be our "root node" in the tree.  Next, we need to find the things that "feed" this root node - that will be steps 2 and 5 - as you can see - 2 and 5 are at the same level of indentation - they "feed" into step 1.  Further, we can see that steps 3 and 4 feed step 2 and that step 6 feeds step 5.  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Putting that together iteratively - we would draw:&lt;br /&gt;&lt;br /&gt;                               1&lt;br /&gt;                              /                              2   5&lt;br /&gt;                            / \                              3   4   6&lt;br /&gt;         &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;And then just read the tree.  In order to get 1 we need 2 and 5 - 2 is "first". In order to get 2, we need 3 and 4.  3 is "first".  That is how I arrived at the psuedo code for:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;For salgrade in (select * from salgrade)&lt;br /&gt;Loop&lt;br /&gt;For emp in ( select * from emp )&lt;br /&gt;Loop&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Full scan SALGRADE is step 3, full scan EMP is step 4 and step 2 is a nested loop - which is roughly equivalent to two "for loops".  Once we get step 2 going like that - we can look at step 5.  Step 5 runs step 6 first - step 6 is the index scan step.  We are taking the output of step 2 here and using that to "feed" this part of the query plan.  So, the output from step 2 is used to perform an index scan - that index scan output is used to TABLE ACCESS BY ROWID the DEPT table and that result is the output of step 1 - our result set.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Now, to make this "interesting", we will run an equivalent query - but we'll mix up the order of the tables in the from clause this time.  Since I am using the rule based optimizer - this will affect the generated query plan (and is just one reason why you DON'T want to use the rule based optimizer!).  We'll use the same logic to build its query plan tree and evaluate how it processed the query:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;scott@ORA920&gt; delete from plan_table;&lt;br /&gt;7 rows deleted.&lt;br /&gt;&lt;br /&gt;scott@ORA920&gt; explain plan for&lt;br /&gt;2  select ename, dname, grade&lt;br /&gt;3    from salgrade, dept, emp&lt;br /&gt;4   where emp.deptno = dept.deptno&lt;br /&gt;5     and emp.sal between salgrade.losal and salgrade.hisal&lt;br /&gt;6  /&lt;br /&gt;Explained.&lt;br /&gt;&lt;br /&gt;scott@ORA920&gt; @?/rdbms/admin/utlxpls&lt;br /&gt;&lt;br /&gt;PLAN_TABLE_OUTPUT&lt;br /&gt;-------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                     |  Name       | Rows  | Bytes&lt;br /&gt;-------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT              |             |       |&lt;br /&gt;|   1 |  NESTED LOOPS                 |             |       |&lt;br /&gt;|   2 |   NESTED LOOPS                |             |       |&lt;br /&gt;|   3 |    TABLE ACCESS FULL          | EMP         |       | &lt;br /&gt;|   4 |    TABLE ACCESS BY INDEX ROWID| DEPT        |       | &lt;br /&gt;|*  5 |     INDEX UNIQUE SCAN         | DEPT_PK     |       | &lt;br /&gt;|*  6 |   TABLE ACCESS FULL           | SALGRADE    |       | &lt;br /&gt;-------------------------------------------------------------------&lt;br /&gt;Predicate Information (identified by operation id):&lt;br /&gt;---------------------------------------------------&lt;br /&gt;5 - access("EMP"."DEPTNO"="DEPT"."DEPTNO")&lt;br /&gt;6 - filter("EMP"."SAL"&lt;="SALGRADE"."HISAL" AND            "EMP"."SAL"&gt;="SALGRADE"."LOSAL")&lt;br /&gt;Note: rule based optimization&lt;br /&gt;&lt;br /&gt;21 rows selected.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Here we see that steps 2 and 6 feed 1, steps 3 and 4 feed 2, and step 5 feeds 4.&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;Drawing the tree:&lt;br /&gt;                               1&lt;br /&gt;                              /                              2   6&lt;br /&gt;                            / \  &lt;br /&gt;                           3   4&lt;br /&gt;                                                                 5 &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;So, the psuedo code logic here is - starting with steps 3 and 4:&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;For emp in ( select * from emp )&lt;br /&gt;Loop&lt;br /&gt;-- using the index&lt;br /&gt;Select * from dept where dept.deptno = emp.deptno&lt;br /&gt;&lt;br /&gt;For salgrade in (select * from salgrade )&lt;br /&gt;Loop&lt;br /&gt; If ( emp.sal between salgrade.losal and salgrade.hisal )&lt;br /&gt; Then&lt;br /&gt;    OUTPUT RECORD;&lt;br /&gt; End if;&lt;br /&gt;End loop&lt;br /&gt;End loop;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;And that is it - if you draw the graphical tree like that and then read it bottom up, left to right, you'll get a good understanding of the "flow" of the data.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Source:  A wonderful article by Tom Kyte at&lt;/span&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:231814117467"&gt;http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:231814117467&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115297443047310537?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115297443047310537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115297443047310537'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/reading-explain-plan.html' title='Reading an Explain Plan'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115296611472648686</id><published>2006-07-15T05:12:00.000-07:00</published><updated>2006-07-15T06:42:00.926-07:00</updated><title type='text'>Tablespace- Disk usage check</title><content type='html'>&lt;span style="font-weight: bold;font-family:verdana;" &gt;Query to check free space in each tablespace&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The following query will show how much free space is left in each tablespace. A space check would be the first step in diagnosing and rectifying errors like&lt;br /&gt;'ORA-01654: unable to extend index scott.my_idx by 128 in tablespace &lt;tablespacename&gt;'&lt;/tablespacename&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="font-family:courier new;"&gt;SELECT df.tablespace_name TABLESPACE,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;       df.total_space TOTAL_SPACE,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;       fs.free_space FREE_SPACE, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;       df.total_space_mb TOTAL_SPACE_MB,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      (df.total_space_mb - fs.free_space_mb) USED_SPACE_MB,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;       fs.free_space_mb FREE_SPACE_MB,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;       ROUND(100 * (fs.free_space / df.total_space),2) PCT_FREE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;FROM (SELECT tablespace_name, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;             SUM(bytes) TOTAL_SPACE,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;             ROUND(SUM(bytes) / 1048576) TOTAL_SPACE_MB&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      FROM   dba_data_files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      GROUP BY tablespace_name) df, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;     (SELECT tablespace_name, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;             SUM(bytes) FREE_SPACE,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;             ROUND(SUM(bytes) / 1048576) FREE_SPACE_MB&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      FROM   dba_free_space&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      GROUP BY tablespace_name) fs&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;WHERE df.tablespace_name = fs.tablespace_name (+)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;ORDER BY PCT_FREE asc;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If you find that a Tablespace is lacking in freeSpace, you might want to add extra space to it by issuing the following command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;ALTER TABLESPACE TABLESPACENAME &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;ADD DATAFILE '/slot01/oracle/mydbdata/tablespacenamexx.dbf' SIZE 500 M&lt;br /&gt;&lt;br /&gt;With Excerpts from: &lt;a href="http://www.psoug.org/reference/tablespaces.html"&gt;http://www.psoug.org/reference/tablespaces.html&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115296611472648686?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115296611472648686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115296611472648686'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/tablespace-disk-usage-check.html' title='Tablespace- Disk usage check'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115296402846136144</id><published>2006-07-15T04:41:00.000-07:00</published><updated>2006-07-15T04:47:08.596-07:00</updated><title type='text'>Unlock an Oracle Account</title><content type='html'>&lt;span style="font-family: verdana;"&gt;To unlock an oracle account do the following&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;$ sqlplus / as sysdba&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; alter user &lt;username&gt; account unlock;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;To check if the account has been unlocked&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; select USERNAME,ACCOUNT_STATUS,LOCK_DATE from dba_users where USERNAME like 'userName';&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115296402846136144?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115296402846136144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115296402846136144'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/unlock-oracle-account.html' title='Unlock an Oracle Account'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115296343310287722</id><published>2006-07-15T04:25:00.000-07:00</published><updated>2006-07-15T04:40:28.606-07:00</updated><title type='text'>Peformance Tuning: Part-3</title><content type='html'>&lt;span style="font-family:verdana;"&gt;In this part, we will look at the importance of Stored Procedures and Sub-Queries&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;6.Stored Procedures&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A stored procedure is a module that is stored in the Oracle database and is written in either PL/SQL (Oracle's proprietory procedural language) or Java. The term procedure is really a misnomer as the "stored procedure" can be a function (ie. it returns a value), a procedure (may have input and/or output parameters), or a package (may contain one or more procedures/functions).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The main performance advantages arise from the fact that there is no need to send data back and forth across the network whilst it is being processed and from the already mentioned fact that stored procedures are tightly coupled with the database and are stored in pre-compiled form which means that the commands are processed much more efficiently than would be the case if an external 3gl was used. The other benefit derives from the fact that the stored procedures will be run on the server hosting the database which is generally a much more powerful computer than the clients.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Stored procedures are ideal when there is a complex piece of business logic that needs to be performed and which involves a lot of database access and if this logic is required in many different places, then even better.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The biggest benefit in the use of stored procedures comes from the use of packages, because whenever any public element of the package is referenced, the whole package is loaded into memory and (assuming it is not aged out) remains in memory for future use. Also if other elements in the package are needed the overhead of calling them is very small, because they are in the same memory area. This means that you can and should group together related program units so that they can share data structures when needed and call each other with minimal overhead.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Having extolled the virtues of stored procedures, you should be aware that pl/sql is not always the best tool, sometimes it is quicker to do things in pure SQL rather than use pl/sql. The other pitfall of using pl/sql is that involves a context switch from SQL which may add a considerable overhead. This is most likley to be a problem when embedding pl/sql function calls in SQL statements. Also the code inside pl/sql functions called from SQL statements will be ignored by EXPLAIN PLAN. This means that a judgement will have to be made on whether the advantages of using stored procedures will outweigh the disadvantages.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;7. Sub Queries&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Sub-queries are queries embedded in another sql statement, often a query. They allow us to answer multi-part questions and are often interchangeable with a join.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Usage&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * in the WHERE, HAVING and START WITH clauses to define the limiting set of rows for SELECT, UPDATE and DELETE statements;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * in the FROM clause of a SELECT statement instead of a table name;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * in INSERT, UPDATE and DELETE statements instead of a table name;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * to define the set of rows to be created in the target table of a CREATE TABLE AS or INSERT INTO statement;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * to define the set of rows to be included by a view or a snapshot in a CREATE VIEW or CREATE SNAPSHOT statement;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * to provide the new values for the specified columns in an UPDATE statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;There are two types of sub queries: correlated and non-correlated&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 102, 102); font-weight: bold; font-style: italic;font-family:verdana;" &gt;* Non Correlated Sub-Queries&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Non-correlated sub queries are executed once for the whole statement, correlated sub queries are executed once per row in the parent query&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Eg:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT name FROM emp WHERE dept_id IN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;(SELECT dept_id FROM dept WHERE budget &gt; 20,000)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The most common use of sub queries is in the WHERE clause of queries to define the limiting condition (i.e. what value(s) rows must have to be of interest), as in the above example.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 102, 102); font-weight: bold; font-style: italic;font-family:verdana;" &gt;* Correlated Sub-Queries&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Correlated sub queries also answer multi-part questions, but are most often used to check for existence or absence of matching records in the parent table and the related table in the sub query. A correlated sub query refers to a column from a table in the parent query.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT *&lt;br /&gt;FROM scott.dept&lt;br /&gt;WHERE NOT EXISTS (SELECT 1 FROM scott.emp WHERE emp.deptno = dept.deptno)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The main performance advantages arise when using sub queries to perform efficient existence checks ie. when you don't actually need to know the value of one or more columns in a row in a table you just need to know whether or not there is a matching row. The EXISTS and NOT EXISTS operators are used for this purpose.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Very often, significant performance improvement can be achieved by modifying queries as below&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;* IN-based sub-queries -  with EXISTS-based sub-queries &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;________ WHERE {someCol} IN ( ... )  ==&gt;  WHERE EXISTS ( ... )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;* 'NOT IN'-based sub-queries - with 'NOT EXISTS'-based sub-queries &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;________ WHERE {someCol} NOT IN ( ... )  ==&gt;  WHERE NOT EXISTS ( ... )&lt;br /&gt;&lt;br /&gt;With Excerpts from:&lt;br /&gt;&lt;a href="http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part7.htm"&gt;http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part7.htm&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part6.htm"&gt;http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part6.htm&lt;/a&gt;&lt;a href="http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part6.htm"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115296343310287722?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115296343310287722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115296343310287722'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/peformance-tuning-part-3.html' title='Peformance Tuning: Part-3'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115294846355379660</id><published>2006-07-14T23:58:00.000-07:00</published><updated>2006-07-15T04:39:43.003-07:00</updated><title type='text'>Peformance Tuning: Part-2</title><content type='html'>&lt;span style="font-family:verdana;"&gt;In the previous post, we saw how FTS and indexes can be helpful. Here we will see the impact of &lt;span style="font-style: italic;"&gt;Joins, Views and De-Normalization&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;3. Joins&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;There are two ways of maximising performance, the first is to design your Oracle database to minmise the number of joins required and to minimise the number of tables in the joins. This requires knowledge of the data structure and the processes performed on the data. If de-normalisation is performed, the performance of queries may be enhanced at the expense of updates and overall flexibility in the system (thereby increasing maintenance costs).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;When using the rule-based optimiser in Oracle, the query can only be tuned by physically changing the order of the tables lsited in the from clause. All other things being equal (eg indexes available), the RBO will use the table listed last in the from clause as the driving table (ie. the table queried first, and the results from which are used to match with the other tables). For the CBO, this is not applicable since it would automatically pick the best table to start with(the smaller table or the table which would return least number of rows).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The best way to optimise a join is to ensure that each join involves only a few tables. If you have a large number of queries requiring 4 or 5 or more tables to be joined then it suggests that your database design should be revisited to minimise the number of joins required. If you have an RBO, make sure that the smallest result set is created first (either use hints or rearrange the order of the tables in the join clause).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Also ensure that the join columns are indexed and that the query does not inadvertently prevent the use of indexes by using functions such as "upper" or making it part of an expression eg.&lt;/span&gt;&lt;br /&gt;"&lt;span style="font-family:courier new;"&gt;WHERE {indexed_field} + 1 = {expression}&lt;/span&gt;". &lt;span style="font-family:verdana;"&gt;In Oracle 8i and above, you can have function-based indexes but these have to be specifically created for each function. You must also be aware that the creation of new indexes may affect the performance of unrelated queries and that de-normalising tables is a trade off between faster queries and slower updates (and reduced flexibility).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;4. Views&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Views are useful for providing&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(a) horizontal or vertical subsets of data from a table (possibly for security reasons)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(b) for hiding the complexity of a query&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(c) for ensuring that exactly the same SQL is used throughout your application&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;(d) to retrieve supplementary information about an entity from a related table.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    *  A horizontal subset of a table is simply a subset of the rows in the table - i.e. a restriction is added to the where clause to limit the rows returned by the query.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * A vertical subset is just a subset of the columns in the table.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Suppose you create a view to hide the details of few rather complicated queries involving the join of several tables. Now, if you have a query which requires an intersection of these two views, you need to check the explain plan so that the execution path is satisfactory.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;A view, by definition is merely a pre-written SQL query, therefore by using the view you are using the pre-defined query, more importantly though, you are using exactly the same query. This means that the query has to be parsed and the execution path determined only once - the first time it is used. Subsequent uses of the query will avoid the overhead of parsing the query and determining the execution plan. Generally this is a good thing. There is a caveat however - if the data is highly skewed and the cost-based optimiser is being used, this may not be desirable as the initially chosen execution plan may not be right for all elements of the data (assuming that the query uses a bind variable and not a constant, of course).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;5. De-Normalization&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:verdana;" &gt;"Normalize until it hurts, denormalize until it works"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;-Jason Couchman, author of Oracle8 Certfied Professional DBA Certification Exam Guide&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Normalization is part of the analysis phase not the design phase. There is a very common misconception among developers that an Oracle database should be normalised to third normal form or above. A fully normalised database will have severe performance problems as Normalisation increases the complexity of the database and increases the number of tables that have to be joined to provide the required information.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;For a large multi-user application an Oracle database in 3NF or above will quickly grind to a halt as your Oracle database struggles to join all the required tables, particularly if any of the tables are quite large.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The space requirements also will be higher as each table will require its own indexes and each update transaction may have to write to several tables instead of just the one.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The information requirements tell us what pieces of data are needed together (eg. customer name, address, telephone number, account transaction history, etc.) and how often, the update requirements tell us which pieces of data are changed, and again how often. With this information a pattern should emerge showing which pieces of data are often required together and whether or not they are updated together. This will then indicate which entities should be combined to form one table.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;There is of course a trade-off between&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;* speed of access and&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;* maintenance/storage requirements caused by duplication of data.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(102, 102, 102); font-weight: bold;font-family:verdana;" &gt;Technique #1 Eliminate joins&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Eg: If an employee and his department name are accessed very often try having the department name column within the EMP table.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(102, 102, 102); font-weight: bold;font-family:verdana;" &gt;Technique #2 Create summary tables&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;This can be achieved either by creating extra tables, or using materialised views in Oracle 8i and above, or by creating extra columns in existing tables.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Eg: Create summary tables to track sales by product, by sales person, by department, by month, by quarter, by year to date and by region.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(102, 102, 102); font-weight: bold;font-family:verdana;" &gt;Technique #3 Include detail info with master&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Eg: If a customer database was required to store customers' past and present addresses, this would usually be normalised to create a seperate customer address table. However, most of the time, previous addresses would not be of much interest so the current address could be stored redundantly in the customer table.&lt;br /&gt;&lt;br /&gt;Source:&lt;br /&gt;&lt;a href="http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part3.htm"&gt;http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part3.htm&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.smart-soft.co.uk/Oracle/oracle-tuning-part4-vw-use.htm"&gt;http://www.smart-soft.co.uk/Oracle/oracle-tuning-part4-vw-use.htm&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115294846355379660?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115294846355379660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115294846355379660'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/peformance-tuning-part-2.html' title='Peformance Tuning: Part-2'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115268708804041377</id><published>2006-07-11T23:02:00.000-07:00</published><updated>2006-07-11T23:51:28.430-07:00</updated><title type='text'>Peformance Tuning: Part-1</title><content type='html'>&lt;span style="font-family: verdana;"&gt;The following are the "weapons" available in your "arsenal" for performance tuning &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   1. Full table scans&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   2. Indexes&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   3. Joins&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   4. Views&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   5. De-normalization&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   6. Stored Procedures&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   7. Sub-queries&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;1. Full table scans&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;This might seem counter-intuitive, surely all queries on a table should be index driven ? Actually, no, they shouldn't. If the table is very large or very small using an index may increase the amount of i/o that is required to access the data and as i/o is the slowest operation, this will cause a degradation in performance.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;1.1 Small Tables&lt;/span&gt; - Because the table is small and because Oracle reads multiple database blocks in one read operation the whole table is scanned in just one read, so however efficient the index, by using it we will be performing unnecessary i/o. The exception to this of course is when the table has been created as an index-only table (available since Oracle 8) which means that the whole table is stored in a B-tree structure&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;1.2 Large Tables&lt;/span&gt; - For Large Tables, the situation when a full table scan is very likely to perform better than an index scan and table lookup is when you are retrieving 10% or more of the data in the table. Of course if you only want to retrieve one row in the table, then you would want to use an index.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;2. Indexes - B-Tree(Balanced Tree) and Bitmap&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;2.1 B-Tree or Balanced-Tree Indexes&lt;/span&gt; (not necessarily Binary Tree, because they may be 'n'-ary trees) are most appropriate when retrieving a small amount of data from a very large table. However, by using Indexes, the performance of updates will be impaired because every time a row is inserted into, deleted from or updated (if the indexed column(s) is/are updated) in the database, the indexes have to be adjusted accordingly.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Therefore having lots of indexes is ideal when the database is mostly read only, but if there are a high proportion of inserts and deletes and only a few read operations, then you would find that indexes would degrade rather than improve performance. You also need to ensure that the particular column(s) you are proposing to index are used frequently as the limiting conditions for a query, if not you will waste a lot of space and degrade database performance.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Another factor to consider with b-tree indexes, is how specific they are. The ideal index is one that refers to only one row in the table, as a primary key does by definition. This reduces considerably the amount of i/o required to retrieve the information, but if the index value relates to many rows because it is not selective, then a lot more data will be retrieved resulting in unnecessary i/o.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;As mentioned before the ideal index will refer to just one row in the table and the same rule applies to concatenated indexes. With concatenated indexes, therefore, the leading column should be the most selective because this will have the biggest impact on the biggest number of queries, assuming that the same column is used most frequently in the limiting conditions of queries.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold; font-style: italic;"&gt;2.2 Bitmap Indexes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If your application is designed to query on non-selective columns, then you should consider the use of bitmap indexes, but only when the data is infrequently updated as bitmap indexes add a considerable overhead to update operations: each new value of the indexed column will require a whole new bitmap to be created and deletes and updates of the indexed column will also require the bitmaps to be adjusted, as there is one bitmap for each distinct value in the column. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Another disadvantage of bit-map indexes in a transaction processing environment is that each update would lock a large number of rows, degrading throughput even more. Bitmaps are valuable in indexing frequently queried, non selective columns in large tables where little or no updating is done, for example in a data warehouse.&lt;br /&gt;&lt;br /&gt;Source:&lt;br /&gt;&lt;a href="http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part1.htm"&gt;http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part1.htm&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part2.htm"&gt;http://www.smart-soft.co.uk/Oracle/oracle-performance-tuning-part2.htm&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115268708804041377?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115268708804041377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115268708804041377'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/peformance-tuning-part-1.html' title='Peformance Tuning: Part-1'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115262698940137432</id><published>2006-07-11T07:09:00.000-07:00</published><updated>2006-07-11T07:09:49.623-07:00</updated><title type='text'>PLSQL Collections and Records</title><content type='html'>&lt;a style="font-family: verdana;" href="http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/05_colls.htm"&gt;http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/05_colls.htm &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115262698940137432?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115262698940137432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115262698940137432'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/plsql-collections-and-records.html' title='PLSQL Collections and Records'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115262114547928475</id><published>2006-07-11T05:26:00.000-07:00</published><updated>2006-07-11T05:32:25.686-07:00</updated><title type='text'>Script to Kill all sessions which are holding EXCLUSIVE Locks</title><content type='html'>&lt;span style="font-family: verdana;"&gt;To remove Exclusive locks, the following crude method can be employed.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Before running this make sure that someone is not genuinely holding a lock ;-)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;DECLARE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  --Cursor to fetch all sessions which are holding Exclusive Locks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  CURSOR c  IS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  SELECT LOCKs.session_id sessionid, ses.serial# serialid&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  FROM v$session ses, sys.dba_lock locks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  WHERE locks.mode_held = 'Exclusive'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  AND ses.sid = locks.session_id;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  c_row c%ROWTYPE;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  l_sql VARCHAR2(100);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  OPEN c;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  LOOP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    FETCH c INTO c_row;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    EXIT WHEN c%NOTFOUND;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    l_sql := 'alter system kill session '''||c_row.sessionid||','||c_row.serialid||'''';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    EXECUTE IMMEDIATE l_sql;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  END LOOP;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  CLOSE c;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;END; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115262114547928475?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115262114547928475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115262114547928475'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/script-to-kill-all-sessions-which-are.html' title='Script to Kill all sessions which are holding EXCLUSIVE Locks'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115259715248439188</id><published>2006-07-10T22:49:00.000-07:00</published><updated>2006-07-10T22:52:32.740-07:00</updated><title type='text'>Why Oracle Database doesn't have a boolean datatype</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Two reasons I could find -&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Since a column defined as below would serve the same purpose&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;--&gt; flag char(1) NOT NULL check (flag in ( 'Y', 'N' ))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. ANSI SQL doesn't require a BOOLEAN datatype.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;However PLSQL does support Boolean variables. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Find a good discussion on this topic at:&lt;/span&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://asktom.oracle.com/pls/ask/f?p=4950:8:2109566621053828525::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:6263249199595"&gt;http://asktom.oracle.com/pls/ask/f?p=4950:8:2109566621053828525::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:6263249199595&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115259715248439188?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115259715248439188'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115259715248439188'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/why-oracle-database-doesnt-have.html' title='Why Oracle Database doesn&apos;t have a boolean datatype'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115244677051830502</id><published>2006-07-09T05:02:00.000-07:00</published><updated>2006-07-09T05:06:10.800-07:00</updated><title type='text'>High Water Mark (HWM)</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/4400/2305/1600/HighWaterMark.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/4400/2305/320/HighWaterMark.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;HWM is a term used with table segments. If a table is envisioned as a series of blocks laid one after the other in a line from left to right, the HWM would be the rightmost block that ever contained data.&lt;br /&gt;&lt;br /&gt;As shown in the figure, HWM starts at the first block for a newly created table. As data is inserted into the table, the HWM rises. If certain records were to be deleted, the HWM remains unchanged. This remains so until the object is rebuilt, truncated or the segment shrunk. DELETE operation does not reset the HWM whereas TRUNCATE will reset the HWM.&lt;br /&gt;&lt;br /&gt;HWM is relevant because - for a Full Table Scan, Oracle scans all blocks under the HWM, even if they contain no data. Hence HWM is a parameter which might affect performance.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115244677051830502?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115244677051830502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115244677051830502'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/high-water-mark-hwm.html' title='High Water Mark (HWM)'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115243895595503340</id><published>2006-07-09T02:54:00.000-07:00</published><updated>2006-07-09T02:55:56.083-07:00</updated><title type='text'>The MERGE Statement</title><content type='html'>&lt;span style="font-family: verdana;"&gt;The MERGE statement (aka "UPSERT") released in Oracle 9i is possibly one of the most useful ETL-enabling technologies built into the Oracle kernel. The MERGE statement enables us to either UPDATE or INSERT a row into a target table in one statement. You simply tell Oracle your rules for determining whether a target row should UPDATEd or INSERTed from the source, and Oracle does the rest.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Prior to 9i, the alternative in SQL was to perform two individual DML statements (one UPDATE and one INSERT, each with opposing predicates). The alternative in PL/SQL was - either try to INSERT a row and if it failed with a DUP_VAL_ON_INDEX exception, then UPDATE the row instead, or try to UPDATE a row, only INSERTing in the event of a SQL%NOTFOUND. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt; CREATE TABLE emp_source&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      2  AS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      3     SELECT * FROM emp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    Table created.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt; SELECT COUNT(*) FROM emp_source;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      COUNT(*)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    ----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            14&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt; CREATE TABLE emp_target&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      2  AS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      3     SELECT * FROM emp WHERE ROWNUM &lt;= 8;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    Table created.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt; SELECT COUNT(*) FROM emp_target;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      COUNT(*)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    ----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;             8&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SQL&gt; BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      2     MERGE INTO emp_target et&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      3        USING ( SELECT * FROM emp_source ) es&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      4        ON    ( et.empno = es.empno )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      5     WHEN MATCHED THEN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      6     UPDATE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      7        SET et.ename  = es.ename&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      8        ,   et.sal    = es.sal&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      9        ,   et.mgr    = es.mgr&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     10        ,   et.deptno = es.deptno&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     11     WHEN NOT MATCHED THEN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     12     INSERT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     13        ( et.empno, et.ename, et.sal, et.mgr, et.deptno )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     14        VALUES&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     15        ( es.empno, es.ename, es.sal, es.mgr, es.deptno );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     16  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     17     DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows merged.');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     18  END;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     19  /&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    14 rows merged.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://www.quest-pipelines.com/newsletter-v4/0903_D.htm"&gt;http://www.quest-pipelines.com/newsletter-v4/0903_D.htm&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115243895595503340?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115243895595503340'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115243895595503340'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/merge-statement.html' title='The MERGE Statement'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115243841372702213</id><published>2006-07-09T02:40:00.000-07:00</published><updated>2006-07-09T02:46:53.860-07:00</updated><title type='text'>How a Deadlock happens</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Activities from Session-1 =&gt; &lt;span style="color: rgb(51, 51, 255);"&gt;Blue&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Activities from &lt;/span&gt;&lt;span style="font-family: verdana;"&gt; Session-2 =&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;Pink&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;SQL&gt; CREATE TABLE dl_1(num NUMBER)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;SQL&gt; CREATE TABLE dl_2(num NUMBER)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;SQL&gt; INSERT INTO dl_1 VALUES(1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;SQL&gt; INSERT INTO dl_2 VALUES(2)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;SQL&gt; COMMIT&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(51, 51, 255);"&gt;SQL&gt; UPDATE dl_1 SET num = 10 WHERE num=1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(204, 51, 204);"&gt;SQL&gt; UPDATE dl_2 SET num = 20 WHERE num=2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(51, 51, 255);"&gt;SQL&gt; UPDATE dl_2 SET num = 200 WHERE num=2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- The above UPDATE from Session-1 will wait till Session-2 has released its lock over this row&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new; color: rgb(204, 51, 204);"&gt;SQL&gt; UPDATE dl_1 SET num = 100 WHERE num=1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(204, 51, 204);"&gt;UPDATE dl_1 SET num = 100 WHERE num=1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(204, 51, 204);"&gt;       *&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(204, 51, 204);"&gt;ERROR at line 1:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(204, 51, 204);"&gt;ORA-00060: deadlock detected while waiting for resource&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;--Here an UPDATE was issued from Session-2. This UPDATE caused Session-2 to wait on Session-1, while Session-1 was already waiting for Session-2. Hence it resulted in a deadlock.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;When a deadlock is detected, Oracle choses one of the two sessions as a "Victim" and the statement which caused the deadlock is rolled back.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115243841372702213?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115243841372702213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115243841372702213'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/how-deadlock-happens.html' title='How a Deadlock happens'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115243726489010146</id><published>2006-07-09T01:34:00.000-07:00</published><updated>2006-07-09T02:27:45.240-07:00</updated><title type='text'>Locking - Optimistic and Pessimistic</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Locks are mechanisms to regulate concurrent access to a &lt;span style="font-style: italic;"&gt;shared resource&lt;/span&gt;(like a row in a table, a stored procedure)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Without proper locking, the classic problem of "&lt;span style="font-weight: bold;"&gt;Lost Updates&lt;/span&gt;" might happen. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;br /&gt;Eg. for "Lost Updates"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. In Session-1, User-1 finds that for EmpName=KING, Salary=10000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. In Session-2, User-2 finds that for EmpName=KING, Salary=10000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. In Session-1, User-1 updates the Salary for KING as 20000 and issues a commit&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. In Session-2, User-2 updates the Salary for KING as 30000 and issues a commit&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: verdana;"&gt;Here the lost update has happened in Step-3; The change made by User-1 is lost, even without User-2 knowing that such an update has happened. &lt;/span&gt;&lt;span style="font-family: verdana;"&gt;To solve this issue, we can use 2 types of locking - Pessimistic and Optimistic&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;** Pessimistic Locking&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;In pessimistic locking, a lock is established as soon as the user indicates his intention of performing an update.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Doing a &lt;span style="font-family: courier new;"&gt;SELECT ... FOR UPDATE&lt;/span&gt; will cause the row to get locked. Unless a &lt;span style="font-family: courier new;"&gt;COMMIT&lt;/span&gt; is issued from the session where a &lt;span style="font-family: courier new;"&gt;SELECT...FOR UPDATE&lt;/span&gt; was done, the row cannot be updated from another session.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Session-1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; SELECT * FROM scott.emp&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 1 WHERE EMPNO = 7369&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 2 FOR UPDATE NOWAIT&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Session-2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;UPDATE scott.emp SET sal = 1601 WHERE empno=7369 -- will hang&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;UPDATE scott.emp SET sal = 1601 WHERE empno=7499 -- will not hang&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; SELECT * FROM scott.emp&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 1 WHERE EMPNO = 7369&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 2 FOR UPDATE NOWAIT;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SELECT * FROM scott.emp&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                    *&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;ERROR at line 1:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;ORA-00054: resource busy and acquire with NOWAIT specified&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;** Optimistic Locking&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;In Optimistic Locking, locking is deferred up to the point right before the update is performed. Here an optimistic assumption is made that the data would not be updated by another user - hence we wait until the last moment to find out if we are right. The disadvantage of optimistic locking is that if another user has updated the same data, the current user may have to requery the data and start over with his update.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;u&gt;Ways of avoiding Lost Updates using optimistic locking&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Remembering data that was initially queried up and using it in future updates to see if anything has changed in between&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; UPDATE scott.emp &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 1 SET sal =801 &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 2 WHERE empno=7369 &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 3 AND sal = 800 -- Here the application checks if the old value has been updated in between.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Adding a timestamp column to the table so that UPDATE statements can use this for Versioning&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;CREATE TABLE timestamp_versioning&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;(deptno NUMBER(2),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; dname VARCHAR2(14),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; loc VARCHAR2(13),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; last_mod TIMESTAMP WITH TIME ZONE DEFAULT SYSTIMESTAMP NOT NULL,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; CONSTRAINT timestamp_versioning_dept_pk PRIMARY KEY(deptno)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Now every row inserted will bear a timestamp and that can be user to track changes in the record.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Using a checksum/Hash computed using one of the following&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- OWA_OPT_LOCK.CHECKSUM&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- DBMS_OBFUSCATION_TOOLKIT.MD5&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- DBMS_CRYPTO.HASH (Uses SHA-1 - Secure Hash Algorithm)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Using ORA_ROWSCN (in Oracle 10g) &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115243726489010146?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115243726489010146'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115243726489010146'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/locking-optimistic-and-pessimistic.html' title='Locking - Optimistic and Pessimistic'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115237321948552575</id><published>2006-07-08T08:37:00.000-07:00</published><updated>2006-07-08T08:40:19.553-07:00</updated><title type='text'>Why Oracle has separate DBWn and LGWR processes</title><content type='html'>&lt;span style="font-family: verdana;"&gt;LGWR does &lt;span style="font-style: italic;"&gt;sequential writes&lt;/span&gt; - so it takes lesser time to do its job. It needs to keep a record of what operations were peformed on the data and hence doesn't have a requirement to post the data to the actual data blocks of interest.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;However DBWn needs to write data to appropriate data blocks - which means it need to first find where to write and then do the writing job.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Since a sequential write takes lesser time, it is advantageous to have separate LGWR and DBWn processes. The user gets better performance because LGWR does it faster sequential job while DBWn does its slow job in the background. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115237321948552575?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115237321948552575'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115237321948552575'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/why-oracle-has-separate-dbwn-and-lgwr.html' title='Why Oracle has separate DBWn and LGWR processes'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115237290875036804</id><published>2006-07-08T08:31:00.000-07:00</published><updated>2006-07-08T08:37:30.200-07:00</updated><title type='text'>Processes in Oracle</title><content type='html'>&lt;span style="font-family:verdana;"&gt;Processes in Oracle can be broadly classified into &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;1. Server Processes&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;2. Background Processes&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;3. Slave Processes&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;______________________________________________________________&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;1. Server Processes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;** Dedicated Server : One to One mapping between connection to the DB and a server process.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;-- This is more appropriate in a non-OLTP environment where there could be long-running transactions. With Shared Server mode, these long running transactions could block other transactions.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;** Shared Server : Many sessions share a pool of server processes; A connection in this case is made to a Dispatcher - not to a dedicated server process.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;-- When using Shared Server configuration, care needs to be taken that sessions do not monopolize the shared server&lt;/span&gt; &lt;span style="font-family:verdana;"&gt;(For example a command like &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;DBMS_LOCK.SLEEP(20)&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; would monopolize the shared server for 20 seconds)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;-- Shared Server configuration is useful for OLTP systems characterized by short, frequent transactions.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;-- If J2EE connection pooling is already being used, using Shared Server configuration can be a performance inhibitor(pooling feature connecting to yet another pooling feature)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;-- Helps reduce the number of OS processes(Unix) / threads(Win).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;______________________________________________________________&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;2. Background Processes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Background processes perform maintenance tasks needed to keep the database running.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;** PMON &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-family:courier new;"&gt;:&lt;/span&gt; Process Monitor - Responsible for cleaning up abnormally terminated connections.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;** SMON&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-family:courier new;"&gt; :&lt;/span&gt; System Monitor - System Level jobs of "garbage collection" - Cleans up temporary space, Coalesces free space&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;** RECO : &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;Recovers transaction left in PreparedState because of crash/loss of connection during a 2-Phase-Commit(2PC)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;** DBWn : &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;Responsible for writing dirty blocks to disk from the buffer cache&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;** LGWR :&lt;/span&gt; &lt;span style="font-family:verdana;"&gt;Responsible for flushing the contents of RedoLogBuffer(in SGA) to disk. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;_________ This is done for &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;_________ (a) every 3 seconds &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;_________ (b) whenever a commit is issued.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;_________ (c) when redo log biffer is one third full or contains 1MB of buffered data.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;** CKPT : &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;Assists LGWR in the CheckPointing process by updating file headers of data files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;** ARCn : &lt;/span&gt;&lt;span style="font-family:verdana;"&gt;Copies Online Redo Log file written by LGWR to another location(better if it is on a different machine) when LGWR fills it up.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;_________ Online Redo Logs written by LGWR are used to fix data files in the event of a power failure&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;_________ Archived Redo Logs written by ARCn are used to fix data files in the event of a hard disk failure&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;To check background processes&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-----------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SELECT paddr, name, description &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;FROM v$bgprocess &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;ORDER BY paddr DESC&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;54668DE8 QMN0 AQ Time Manager Process 0    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;54668A2C CJQ0 Job Queue Coordinator        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;54668670 RECO distributed recovery         &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;546682B4 SMON System Monitor Process       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;54667EF8 CKPT checkpoint                   &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;54667B3C LGWR Redo etc.                    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;54667780 DBW0 db writer process 0          &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;546673C4 PMON process cleanup              &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;00 ----- DIAG diagnosibility process       &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;00 ----- FMON File Mapping Monitor Process &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;00 ----- DBW1 db writer process 1          &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;00 ----- ARC1 Archival Process 1           &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;00 ----- ARC0 Archival Process 0           &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;00 ----- MRP0 Managed Standby Recovery     &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;00 ----- LCK0 Lock Process 0               &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;______________________________________________________________&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;3. Slave Processes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;** I/O Slaves : Used to emulate asynchronous I/O for systems/devices that do not support it. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Eg: For tape devices which do not support async I/O&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;** Parallel Query Slaves : Helps to break down query plan into multiple pieces which can be executed by multiple processors. Useful when multiple processors are available at disposal and a query needs to be executed over a large table.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115237290875036804?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115237290875036804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115237290875036804'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/processes-in-oracle.html' title='Processes in Oracle'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115237101170928109</id><published>2006-07-08T08:02:00.000-07:00</published><updated>2006-07-08T08:03:31.890-07:00</updated><title type='text'>Two-Phase Commit Mechanism</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Unlike a transaction on a local database, a distributed transaction involves altering data on multiple databases. Consequently, distributed transaction processing is more complicated, because Oracle must coordinate the committing or rolling back of the changes in a transaction as a self-contained unit. In other words, the entire transaction commits, or the entire transaction rolls back.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Oracle ensures the integrity of data in a distributed transaction using the two-phase commit mechanism. In the prepare phase, the initiating node in the transaction asks the other participating nodes to promise to commit or roll back the transaction. During the commit phase, the initiating node asks all participating nodes to commit the transaction. If this outcome is not possible, then all nodes are asked to roll back.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;All participating nodes in a distributed transaction should perform the same action: they should either all commit or all perform a rollback of the transaction. Oracle automatically controls and monitors the commit or rollback of a distributed transaction and maintains the integrity of the global database (the collection of databases participating in the transaction) using the two-phase commit mechanism. This mechanism is completely transparent, requiring no programming on the part of the user or application developer.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The commit mechanism has the following distinct phases, which Oracle performs automatically whenever a user commits a distributed transaction:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. &lt;span style="font-weight: bold;"&gt;Prepare phase&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The initiating node, called the global coordinator, asks participating nodes other than the commit point site to promise to commit or roll back the transaction, even if there is a failure. If any node cannot prepare, the transaction is rolled back.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. &lt;span style="font-weight: bold;"&gt;Commit phase&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If all participants respond to the coordinator that they are prepared, then the coordinator asks the commit point site to commit. After it commits, the coordinator asks all other nodes to commit the transaction.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. &lt;span style="font-weight: bold;"&gt;Forget phase&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The global coordinator forgets about the transaction. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.utexas.edu/its/unix/reference/oracledocs/v92/B10501_01/server.920/a96521/ds_txns.htm"&gt;http://www.utexas.edu/its/unix/reference/oracledocs/v92/B10501_01/server.920/a96521/ds_txns.htmhttp://www.utexas.edu/its/unix/reference/oracledocs/v92/B10501_01/server.920/a96521/ds_txns.htm&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115237101170928109?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115237101170928109'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115237101170928109'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/two-phase-commit-mechanism.html' title='Two-Phase Commit Mechanism'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115236685903145970</id><published>2006-07-08T06:41:00.000-07:00</published><updated>2006-07-08T06:54:19.416-07:00</updated><title type='text'>Trivia on AUTOTRACE</title><content type='html'>&lt;span style="font-family: verdana;"&gt;When &lt;/span&gt;&lt;span style="font-family: courier new;"&gt;AUTOTRACE&lt;/span&gt; &lt;span style="font-family: verdana;"&gt;is enabled, following actions are performed during DML operations&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. A new session is created using the current connection(if secondary session does not already exist)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. The new session will query&lt;/span&gt;&lt;span style="font-family: courier new;"&gt; V$SESSTAT&lt;/span&gt; &lt;span style="font-family: verdana;"&gt;view to remember initial statistics values for the session where DML is done.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. DML is run from original session&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Upon completion of DML, secondary session will query&lt;/span&gt; &lt;span style="font-family: courier new;"&gt;V$SESSTAT&lt;/span&gt; &lt;span style="font-family: verdana;"&gt;once again to find the difference in statistics&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The reason behind having a secondary session doing the monitoring job is that, if it were do accomplish the same from the primary session, the statistics reported would include the cost of monitoring as well.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;To verify this, query the v$session before and after setting&lt;/span&gt; &lt;span style="font-family: courier new;"&gt;AUTOTRACE ON.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; SELECT username UNAME, sid, serial# SLNO, server, paddr, status&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 2 FROM v$session&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 3 WHERE username = 'uName';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 4 /&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;UNAME SID SLNO SERVER __ PADDR __ STATUS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;----- --- ---- --------- -------- ------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;uName 153 3196 DEDICATED AE4CF614 ACTIVE&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; SET AUTOTRACE ON STATISTICS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; SELECT username UNAME, sid, serial# SLNO, server, paddr, status&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 2 FROM v$session&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 3 WHERE username = 'uName';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; 4 /&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;UNAME SID SLNO SERVER __ PADDR __ STATUS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;----- --- ---- --------- -------- --------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;uName 151 1511 DEDICATED AE4CF614 INACTIVE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;uName 153 3196 DEDICATED AE4CF614 ACTIVE&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Statistics&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;----------------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;... &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115236685903145970?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115236685903145970'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115236685903145970'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/trivia-on-autotrace.html' title='Trivia on AUTOTRACE'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115236362490674816</id><published>2006-07-08T05:58:00.000-07:00</published><updated>2006-07-08T07:23:20.806-07:00</updated><title type='text'>Difference between a Connection and a Session</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/4400/2305/1600/ConnectionsVsSessions.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/4400/2305/320/ConnectionsVsSessions.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Connection&lt;/span&gt;: Physical path from client to Oracle instance. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Options are &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;1. client --connected to-- dispatcher&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;2. client --connected to-- dedicated server&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;3. client --connected to-- Oracle Connection Manager(CMAN)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Session&lt;/span&gt;: Logical entity in the instance. Collection of data structures represents a unique sessions. "SQL statements are execeuted", "transactions are committed" and "stored procedures are run" in a session.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:verdana;" &gt;A connection may have zero or more sessions.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-style: italic;"&gt;A session may have have zero or one connection&lt;/span&gt;.(zero in cases where OracleNet connection pooling is employed and the session is idle)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115236362490674816?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115236362490674816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115236362490674816'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/difference-between-connection-and.html' title='Difference between a Connection and a Session'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115215268373993762</id><published>2006-07-05T18:59:00.000-07:00</published><updated>2006-07-05T19:24:44.130-07:00</updated><title type='text'>Summary of Storage Hierarchies in Oracle</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. A &lt;span style="font-weight: bold;"&gt;database&lt;/span&gt; is made up of one or more tablespaces&lt;br /&gt;&lt;br /&gt;2. A &lt;span style="font-weight: bold;"&gt;tablespace&lt;/span&gt; is made up of one or more datafiles.&lt;br /&gt;These files might be OS managed files in a file system, raw partitions, ASM managed database files or a file on a clustered file system. A tablespace contains segments&lt;br /&gt;&lt;br /&gt;3. A &lt;span style="font-weight: bold;"&gt;segment&lt;/span&gt; (TABLE, INDEX,...) is made up of one or more extents. A segment exists in a tablespace, but may have data in multiple data files within that tablespace.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4. An &lt;span style="font-weight: bold;"&gt;extent&lt;/span&gt; is a logically contiguous set of blocks on a disk. An extent exists within a single data file within a tablespace.&lt;br /&gt;&lt;br /&gt;5. A &lt;span style="font-weight: bold;"&gt;block&lt;/span&gt; is the smallest unit of allocation in the database. It is the smallest unit of I/O used by a database.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115215268373993762?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115215268373993762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115215268373993762'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/summary-of-storage-hierarchies-in.html' title='Summary of Storage Hierarchies in Oracle'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115199283438804974</id><published>2006-07-03T22:47:00.000-07:00</published><updated>2006-07-03T23:00:34.896-07:00</updated><title type='text'>Index Organized Tables</title><content type='html'>&lt;span style="font-family: verdana;"&gt;In an Index Organized Table(IOT), data is stored and sorted by primary key(s).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;/span&gt;&lt;span style="font-family: verdana;"&gt;&lt;/span&gt;&lt;span style="font-family: verdana;"&gt;A table that is accessed exclusively by its Primary Key is a good candidate for IOT. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Eg: Consider the following table&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;CREATE TABLE heap_org_table_test&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;(&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;empname VARCHAR2(50),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;empid   NUMBER,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;deptid NUMBER&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;PRIMARY KEY(empname, empid, deptid)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Here the table consists solely of columns from the Primary Key. The storage overhead in this case would be 100% since the size of the table and the Primary Key Index would be comparable. In such a case it is better to use an IOT.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Apart from the storage benefit, a key aspect about IOT is that it helps reduce the number of Physical I/O and Buffer-Gets. This is because in an IOT, related data is co-located. Hence the database doesn't have to go over multiple blocks to find what it needs.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-family: verdana;"&gt;Differences between Heap Organized and Index Organized Tables&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-style: italic;"&gt;Heap Organized Tables &lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: verdana;"&gt;- disk usage for data + index (assuming the table has an index)&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: verdana;"&gt;- no guarantee about order of rows - unless an 'order by' is used with a SELECT&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: verdana; font-style: italic;"&gt;Index Organized Tables &lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: verdana;"&gt;- disk usage for data alone&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: verdana;"&gt;- data is stored in indexed order&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;An interesting point with IOT is that although it is called a 'Table', Oracle internally uses an INDEX segment to store it. Data for an index-organized table is stored in B-tree index leaves in a sorted order based on the table's primary key so that changes to that data, such as adding, updating, or deleting rows, require an update to the index only. The following query confirms that an index segment is being used.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SELECT dbms_metadata.get_ddl('TABLE', '&lt;iot_table_name&gt;') &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;FROM dual&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The metadata would indicate that the underlying segment is an index. For example the output of the above query would have a PCTFREE parameter but not a PCTUSED. This is because in an index, data must go where it belongs - unlike in a randomly-organized Table (Heap Organized) where the database has the option of storing the same data on any block - hence PCTUSED would not be relevant with IOT.&lt;br /&gt;&lt;br /&gt;Example for IOT creation&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;CREATE TABLE t&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;(x INT PRIMARY KEY&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; y VARCHAR2(25)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; z DATE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new; color: rgb(0, 0, 0); font-weight: bold;"&gt;ORGANIZATION INDEX&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115199283438804974?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115199283438804974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115199283438804974'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/index-organized-tables.html' title='Index Organized Tables'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115195776932218811</id><published>2006-07-03T13:15:00.000-07:00</published><updated>2006-07-03T13:16:09.893-07:00</updated><title type='text'>Data Files</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Any real DataBase has atleast 3 Data Files for the following purposes&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. &lt;span style="font-family: courier new;"&gt;SYSTEM&lt;/span&gt; data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. &lt;span style="font-family: courier new;"&gt;SYSAUX&lt;/span&gt; data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. &lt;span style="font-family: courier new;"&gt;USER&lt;/span&gt; data&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; font-weight: bold;"&gt;File System Mechanisms&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. 'Cooked' OS Based file system&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  Files managed via the OS. Viewble by doing an ls/dir on unix/windows&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  Typically these are buffered by the OS. ie. the OS will cache info as you read/write.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Raw partitions&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  Raw disk storage available to Oracle as one large chunk. Not part of the filesystem&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  Not buffered like OS Files(which is good for a DB)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. ASM - Automatic Storage Management&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  Database specific FileSystem - feature of 10g&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Clustered FileSystem&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  Brings benefits of 'Cooked' OS FileSystem to Clustered files.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115195776932218811?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115195776932218811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115195776932218811'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/data-files.html' title='Data Files'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115195253793107003</id><published>2006-07-03T11:47:00.000-07:00</published><updated>2006-07-03T11:48:59.303-07:00</updated><title type='text'>File Types in an Oracle Database</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. Data Files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; Hold tables, indexes and other segments&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Temp Files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; For disk based sorts and temporary storage&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Control Files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; Contains info about where dataFiles, tempFiles and redoLogFiles are + Metadata about their state&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Redo log Files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; Contains transaction logs&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. Password Files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; For authenticating users performing admin tasks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;6. Parameter Files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; Where to find Control Files; How bug memory structures should be etc&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;7. Trace Files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; Diagnostic files generated in error conditions&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;8. Alert Files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; Contains info about "Expected" events&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;9. Change Tracking Files (10g)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; Facilitates incremental backup of Oracle data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;10. Flashback Log Files (10g)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---&gt; Stores "before images" of database blocks to facilitate '&lt;span style="font-family: courier new;"&gt;FLASHBACK DATABASE&lt;/span&gt;' command&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115195253793107003?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115195253793107003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115195253793107003'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/file-types-in-oracle-database.html' title='File Types in an Oracle Database'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115187579331921242</id><published>2006-07-02T14:23:00.000-07:00</published><updated>2006-07-02T14:29:53.583-07:00</updated><title type='text'>Dedicated and Shared Server Connections</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/4400/2305/1600/Dedicated_And_Shared_Connections.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/4400/2305/320/Dedicated_And_Shared_Connections.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;span style="font-family: verdana; color: rgb(51, 51, 255); font-weight: bold;"&gt;Blue Lines - Dedicated Connection&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Flow&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Client initiates request&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Listener does fork/exec to create new process/thread for dedicated server&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Client establishes connection to Dedicated server&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Dedicated server directly interacts with SGA&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana; color: rgb(204, 51, 204); font-weight: bold;"&gt;Pink Lines - Shared Connection&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Flow&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Client initates request&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Listener replies back with Dispatcher Port number&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Client connects to Dispatcher&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Dispatcher places Client-Request on Request queue&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. Shared Server finds the request -processes it - and places response on Response Queue&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;6. Dispatcher monitors Response Queue - finds the response - and sends it to Client&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115187579331921242?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115187579331921242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115187579331921242'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/dedicated-and-shared-server.html' title='Dedicated and Shared Server Connections'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115187233499124605</id><published>2006-07-02T11:17:00.000-07:00</published><updated>2006-07-02T13:32:15.313-07:00</updated><title type='text'>Difference between a Database and an Instance</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/4400/2305/1600/DB-Vs-INSTANCE.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/4400/2305/320/DB-Vs-INSTANCE.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Database&lt;/span&gt;: A colection of physical OS Files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-weight: bold;"&gt;Instance&lt;/span&gt; : A set of Oracle background processes + shared memory area.&lt;/span&gt;  &lt;span style="font-family:verdana;"&gt;&lt;br /&gt;&lt;br /&gt;A database may be mounted and opened by many instances (as in RAC)&lt;/span&gt; &lt;span style="font-family:verdana;"&gt;&lt;br /&gt;An instance will have at most one database associated with it.&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Oracle V$views related to a database&lt;/span&gt; &lt;span style="font-family:courier new;"&gt;&lt;br /&gt;1. v$datafile&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;2. v$logfile&lt;/span&gt; &lt;span style="font-family:courier new;"&gt;&lt;br /&gt;3. v$controlfile &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115187233499124605?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115187233499124605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115187233499124605'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/difference-between-database-and.html' title='Difference between a Database and an Instance'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115175636776649859</id><published>2006-07-01T04:58:00.000-07:00</published><updated>2006-07-01T05:19:28.170-07:00</updated><title type='text'>Hash Joins</title><content type='html'>&lt;span style="font-family: verdana;"&gt;A Hash Join is a join which utilizes Hash functions and Hashtables for performing efficient joins.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Consider 2 tables - EMP and DEPT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;EMP  - 10000 records&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;DEPT -   500 records&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If these 2 tables are being joined on the basis of a common column, say deptno (which appears in both EMP and DEPT), there could be 2 ways of performing the join&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Through &lt;span style="font-weight: bold;"&gt;Nested Loops&lt;/span&gt; - In a nested loop, the execution path turns out to be somewhat like 2 nested FOR loops.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;In other words, for each record in EMP, a suitable record in DEPT needs to be found - if deptno is an indexed column, an INDEX SCAN on DEPT would be performed for each record in EMP.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Through the use of &lt;span style="font-weight: bold;"&gt;Hash Joins&lt;/span&gt; - For performing a Hash join, Oracle constructs a Hash over the smaller table (here DEPT). This Hash would contain&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;information in the format {HashValue -&gt; dept details}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;For obtaining the Hashvalue, a Hash Function is used - this is a one-way function (many-to-one mapping from domain to range). To perform the query, Oracle would initially construct an in-memory Hash(if possible an in-memory Hash is constructed, or else it may use the TEMP tablespace); then within the loop over EMP table, this Hashtable would be used to efficiently find out the associated DEPT info. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;NOTE: It is possible that multiple values of deptno map to the same Hash value. In this case, once the dept information is found using the Hashtable, Oracle will determine the appropriate row using the deptno.(and that doesn't cost a lot, since with a proper Hashing Function, we dont expect all deptno values to be Hashed to the same value)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Approach #2 (Hashing) is efficient when the number of rows is high in the tables being joined. For lesser number of rows, performing an INDEX SCAN would be efficient since that would avoid the cost of creating the Hash structure.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;For an excellent Viewlet explaining Hash joins, visit&lt;/span&gt;&lt;br /&gt;&lt;a href="http://asktom.oracle.com/%7Etkyte/hj/hj.html"&gt;&lt;span style="font-family: verdana;"&gt;http://asktom.oracle.com/~tkyte/hj/hj.html &lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:65506569258230"&gt;http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:65506569258230&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115175636776649859?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115175636776649859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115175636776649859'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/hash-joins.html' title='Hash Joins'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115175001130277052</id><published>2006-07-01T03:31:00.000-07:00</published><updated>2006-07-01T03:36:08.346-07:00</updated><title type='text'>TNSNAMES.ORA, LISTENER.ORA and SQLNET.ORA</title><content type='html'>&lt;span style="font-family:verdana;"&gt;In its most basic form, Oracle uses three files (listener.ora, tnsnames.ora &amp; sqlnet.ora) for network configuration. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Listener.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The listerner.ora file contains server side network configuration parameters. It can be found in the ORACLE_HOME/network/admin directory on the server. Here is an example of a listener.ora file from Windows 2000:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    # LISTENER.ORA Network Configuration File: C:\Oracle\817\network\admin\listener.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    # Generated by Oracle configuration tools.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    LISTENER =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      (DESCRIPTION_LIST =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (DESCRIPTION =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (ADDRESS_LIST =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (ADDRESS_LIST =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            (ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (DESCRIPTION =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (PROTOCOL_STACK =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            (PRESENTATION = GIOP)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            (SESSION = RAW)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 2481))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    SID_LIST_LISTENER =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      (SID_LIST =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (SID_DESC =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (SID_NAME = PLSExtProc)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (ORACLE_HOME = C:\Oracle\817)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (PROGRAM = extproc)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (SID_DESC =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (GLOBAL_DBNAME = ORCL.WORLD)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (ORACLE_HOME = C:\Oracle\817)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (SID_NAME = ORCL)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;After the listener.ora file is amended the listener should be restarted or reloaded to allow the new configuation to take effect:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    C:&gt; lsnrctl stop&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    C:&gt; lsnrctl start&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    C:&gt; lsnrctl reload&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Tnsnames.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The tnsnames.ora file contains client side network configuration parameters. It can be found in the ORACLE_HOME/network/admin or ORACLE_HOME/net80/admin directory on the client. This file will also be present on the server if client style connections are used on the server itself. Basically the listener.ora file is used on a server, and it helps make the connections between client requests and the database instance(s) on the server.  The tnsnames.ora file is used on the client, and it points to a particular entry in a listener.ora file on a server.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Here is an example of a tnsnames.ora file from Windows 2000:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    # TNSNAMES.ORA Network Configuration File: C:\Oracle\817\network\admin\tnsnames.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    # Generated by Oracle configuration tools.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    ORCL.WORLD =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      (DESCRIPTION =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (ADDRESS_LIST =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (CONNECT_DATA =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (SERVICE_NAME = ORCL.WORLD)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    INST1_HTTP.WORLD =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      (DESCRIPTION =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (ADDRESS_LIST =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (CONNECT_DATA =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (SERVER = SHARED)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (SERVICE_NAME = MODOSE)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (PRESENTATION = http://admin)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    EXTPROC_CONNECTION_DATA.WORLD =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      (DESCRIPTION =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (ADDRESS_LIST =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        (CONNECT_DATA =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (SID = PLSExtProc)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;          (PRESENTATION = RO)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:verdana;" &gt;Sqlnet.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The sqlnet.ora file contains client side network configuration parameters. It can be found in the ORACLE_HOME/network/admin or ORACLE_HOME/net80/admin directory on the client. This file will also be present on the server if client style connections are used on the server itself. Here is an example of an sqlnet.ora file from Windows 2000:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    # SQLNET.ORA Network Configuration File: C:\Oracle\817\network\admin\sqlnet.ora&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    # Generated by Oracle configuration tools.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    SQLNET.AUTHENTICATION_SERVICES= (NTS)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    NAMES.DEFAULT_DOMAIN = WORLD&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Source: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.oracle-base.com/articles/misc/OracleNetworkConfiguration.php"&gt;http://www.oracle-base.com/articles/misc/OracleNetworkConfiguration.php&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115175001130277052?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115175001130277052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115175001130277052'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/07/tnsnamesora-listenerora-and-sqlnetora.html' title='TNSNAMES.ORA, LISTENER.ORA and SQLNET.ORA'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115157302589147063</id><published>2006-06-29T02:03:00.000-07:00</published><updated>2006-06-29T02:23:46.020-07:00</updated><title type='text'>CUBE</title><content type='html'>&lt;span style="font-family: verdana;"&gt;CUBE applies the aggregation function to all possible combinations.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;ie. if you have N fields in the CUBE clause, you would have 2^N levels of aggregation.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Below, we have the same data(as in the ROLLUP example) after applying a CUBE&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;ROLLUP based Query&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;select country, state, mon, sum(sales) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;from sales_data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;group by rollup (country, state, mon)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;CUBE based query&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;----------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;select country, state, mon, sum(sales) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;from sales_data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;group by cube (country, state, mon)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;CUBE Result Set&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;---------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;CN | ST | MON | SALES&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;---+----+-----+------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | -- | --- |416000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | -- | FEB |216000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | -- | JAN |200000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | AP | --- | 61000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | AP | FEB | 31000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | AP | JAN | 30000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | CA | --- |151000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | CA | FEB | 81000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | CA | JAN | 70000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | ND | --- | 82000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | ND | FEB | 42000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | ND | JAN | 40000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | NJ | --- |122000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | NJ | FEB | 62000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-- | NJ | JAN | 60000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;IN | -- | --- |143000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;IN | -- | FEB | 73000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;IN | -- | JAN | 70000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;IN | AP | --- | 61000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;IN | AP    | FEB | 31000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;IN | AP | JAN | 30000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;IN | ND | --- | 82000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;IN | ND | FEB | 42000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;IN | ND | JAN | 40000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;US | -- | --- |273000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;US | -- | FEB |143000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;US | -- | JAN |130000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;US | CA | --- |151000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;US | CA | FEB | 81000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;US | CA | JAN | 70000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;US | NJ | --- |122000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;US | NJ | FEB | 62000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;US | NJ | JAN | 60000 &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115157302589147063?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115157302589147063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115157302589147063'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/cube.html' title='CUBE'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115156518703009969</id><published>2006-06-29T00:08:00.000-07:00</published><updated>2006-06-29T00:15:45.536-07:00</updated><title type='text'>ROLLUP</title><content type='html'>&lt;span style="font-family:verdana;"&gt;ROLLUP enables a SELECT statement to calculate multiple levels of subtotals across a specified group of dimensions. The ROLLUP extension is highly efficient, adding minimal overhead to a query.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ROLLUP creates subtotals at n+1 levels, where n is the number of grouping columns. For instance, if a query specifies ROLLUP on grouping columns of time, region, and department (n=3), the result set will include rows at four aggregation levels.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;This queries below perform the same task - only that the second one uses ROLLUP&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Query - A&lt;br /&gt;-----------&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;select s, a, b, c from (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  select sum(n) s, a, b, c from test_groupby group by a, b, c&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    union&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  select sum(n) s, a, b, null from test_groupby group by a, b, null&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    union&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  select sum(n) s, a, null, null from test_groupby group by a, null, null&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    union&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  select sum(n), null, null, null from test_groupby&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;order by a, b, c;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Query - B&lt;br /&gt;-----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;select sum(n), a, b, c from test_groupby group by rollup (a, b, c);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;What ROLLUP does&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Data in SALES table&lt;br /&gt;---------------------&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;CN | ST | MON | SALES&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;---+----+-----+------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;US | CA | JAN | 70000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;US | CA | FEB | 81000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;US | NJ | JAN | 60000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;US | NJ | FEB | 62000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;IN | AP | JAN | 30000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;IN | AP | FEB | 31000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;IN | ND | JAN | 40000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;IN | ND | FEB | 42000&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;After ROLLUP action&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;CN | ST | MON | SALES&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;---+----+-----+------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;US | CA | JAN | 70000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;US | CA | FEB | 81000&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);font-family:courier new;" &gt;US | CA |     --- |151000  &lt;- US, CA all MON&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;US | NJ | JAN | 60000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;US | NJ | FEB | 62000&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);font-family:courier new;" &gt;US | NJ |     --- |122000  &lt;- US, NJ all MON&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;font-family:courier new;" &gt;US |    -- |     --- |273000  &lt;- US all STATES and MON&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;IN | AP | JAN | 30000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;IN | AP | FEB | 31000&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);font-family:courier new;" &gt;IN | AP |     --- | 61000  &lt;- IN, AP all MON&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;IN | ND | JAN | 40000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;IN | ND | FEB | 42000&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);font-family:courier new;" &gt;IN | ND |     --- | 82000  &lt;- IN, ND all MON&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 153, 0);font-family:courier new;" &gt;IN |    -- |     --- |143000  &lt;- IN all STATES and MON&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102); font-weight: bold;font-family:courier new;" &gt;-- |    -- |     --- |417000  &lt;- Combined - all COUNTRIES, STATES and MON&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 102, 102);font-family:courier new;" &gt;&lt;span style="color: rgb(0, 0, 0); font-family: verdana;"&gt;With Excerpts from: &lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.adp-gmbh.ch/ora/sql/group_by_rollup.html"&gt;&lt;span style="color: rgb(0, 0, 0); font-family: verdana;"&gt;http://www.adp-gmbh.ch/ora/sql/group_by_rollup.html&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 102, 102); font-weight: bold;font-family:courier new;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115156518703009969?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115156518703009969'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115156518703009969'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/rollup.html' title='ROLLUP'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115148536367667222</id><published>2006-06-28T01:59:00.000-07:00</published><updated>2006-06-28T02:02:43.706-07:00</updated><title type='text'>Why Bind Parameters improve performance</title><content type='html'>&lt;span style="font-family: verdana;"&gt;When a query is fired, the database tries to parse it and obtain an execution plan. This operation is quite costly and overall performance of your application can be improved if the number of parsing operations is reduced. Bind parameters become useful in such a scenario. When a bind parameter appears in a query, the query-format remains unchanged although the actual bind value may change. Hence reparsing can be avoided with the usage of bind.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;To illustrate, consider the following 4 queries&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. select * from employees&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;where id = 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. select * from employees&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;where id = 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. select * from employees&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;where id = :1 -- With Bind = 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. select * from employees&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;where id = :1 -- With Bind = 4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Run these 4 queries from SQL*Plus and then run the below query.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;select name, sharable_mem, executions &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;from v$db_object_cache&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;where name like 'select * from employees where %'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Results&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;-------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;select * from employees where id = 1    7480    1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;select * from employees where id = 1    1446    0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;select * from employees where id = :1    7480    2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;select * from employees where id = :1    1447    0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;select * from employees where id = 2    7480    1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;select * from employees where id = 2    1446    0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;From the result set, it can been seen that the Query which had binds has only one entry in v$db_object_cache (with executions=2) - whereas for the ones without binds, there are multiple entries. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115148536367667222?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115148536367667222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115148536367667222'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/why-bind-parameters-improve.html' title='Why Bind Parameters improve performance'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115147142556490085</id><published>2006-06-27T22:09:00.001-07:00</published><updated>2006-07-08T23:55:23.116-07:00</updated><title type='text'>DUAL table in Oracle</title><content type='html'>&lt;span style="font-family:verdana;"&gt;1. Dual is a table which is created by oracle along with the data dictionary. It consists of exactly one column whose name is dummy  and one record. The value of that record is X.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;font-family:verdana;" &gt;SQL&gt; desc dual&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;font-family:verdana;" &gt; Name                     Null?    Type&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;font-family:verdana;" &gt; ----- ----- -----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;font-family:verdana;" &gt; DUMMY _____                            VARCHAR2(1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;font-family:verdana;" &gt;SQL&gt; select * from dual;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;font-family:verdana;" &gt;D&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;font-family:verdana;" &gt;-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;font-family:verdana;" &gt;X&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;2. The owner of dual is SYS but dual can be accessed by every user. As dual contains exactly one row (unless someone fiddled with it), it is guaranteed to return exactly one row in select statements if a constant expression is selected against dual, such as in - select sysdate from dual;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Although it is possible to delete the one record, or insert additional records, one really should not do that!. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;3. DUAL is owned by SYS.  SYS owns the data dictionary, therefore DUAL is part of the data dictionary.  You are not to &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;modify the data dictionary via SQL ever -- wierd things can and will happen. We can make many strange things happen &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;in Oracle by updating the data dictionary. It is neither recommend, supported nor a very good idea.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;4. What is the dual table, what is its purpose.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Dual is just a convienence table. It isn't mandatory to use DUAL, you can use any other table with a similar structure(&lt;span style="font-style: italic;"&gt;1 column and 1 row&lt;/span&gt;).  The advantage to dual is that the optimizer understands dual is a special one row, one column table -- when you use it in queries, it uses this knowledge when developing the plan.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;5. Why does it contain only one column with datatype varchar2, why not number .&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Truly, why no.  Why not a date you would ask then.  The column, its name, its datatype and even its value are NOT relevant.  DUAL exists solely as a means to have a 1 row table we can reliably select from.  Thats all.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;6. Does it contain one row by default.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Yes, when we build the database, we build dual and put a single row in it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;SVRMGR&gt; select * from dual;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;D&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;-&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;X&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;1 row selected.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;7 Trivia &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;SVRMGR&gt; alter database close;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Statement processed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;SVRMGR&gt; select * from dual;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ADDR     INDX       INST_ID    D&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;-------- ---------- ---------- -&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;01680288          0          1 X&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;1 row selected.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;closing the database makes this special dual table come into play (there for RMAN to have a dual table to select from even when the database isn't fully up)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;8. Recreating a DUAL table which was dropped by SYS user&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;step 1: revoke all privileges except for CREATE SESSION from this friend.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;step 2: connect as sysdba&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;step 3: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;create table dual      &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;  (dummy varchar2(1))  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;  storage (initial 1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;insert into dual values('X')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;create public synonym dual for dual&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;grant select on dual to public with grant option&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;/&lt;br /&gt;&lt;br /&gt;Source:&lt;br /&gt;&lt;a href="http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1562813956388"&gt;http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1562813956388&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.adp-gmbh.ch/ora/misc/dual.html"&gt;http://www.adp-gmbh.ch/ora/misc/dual.html&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115147142556490085?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115147142556490085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115147142556490085'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/dual-table-in-oracle_27.html' title='DUAL table in Oracle'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115147014047354288</id><published>2006-06-27T21:45:00.001-07:00</published><updated>2006-06-27T21:49:00.480-07:00</updated><title type='text'>Queries for obtaining Shared Pool Information</title><content type='html'>&lt;a style="font-family: verdana;" href="http://vsbabu.org/oracle/sect13.html"&gt;http://vsbabu.org/oracle/sect13.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Related Tables :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. v$shared_pool_reserved&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. v$db_object_cache&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. v$librarycache&lt;/span&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://vsbabu.org/oracle/sect13.html"&gt; &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115147014047354288?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115147014047354288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115147014047354288'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/queries-for-obtaining-shared-pool.html' title='Queries for obtaining Shared Pool Information'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115144128996394195</id><published>2006-06-27T13:47:00.000-07:00</published><updated>2006-06-27T13:48:09.986-07:00</updated><title type='text'>Cache-Hits and Cache-Misses</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. Oracle maintains its own buffer cache inside the system global area (SGA) for each instance. A properly sized buffer cache can usually yield a cache hit ratio over 90%, meaning that nine requests out of ten are satisfied without going to disk.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If a buffer cache is too small, the cache hit ratio will be small and more physical disk I/O will result. If a buffer cache is too big, then parts of the buffer cache will be under-utilized and memory resources will be wasted. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Checking The Cache Hit Ratio&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Oracle maintains statistics of buffer cache hits and misses. The following query will show you the overall buffer cache hit ratio for the entire instance since it was started:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     SELECT (P1.value + P2.value - P3.value) / (P1.value + P2.value)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     FROM   v$sysstat P1, v$sysstat P2, v$sysstat P3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     WHERE  P1.name = 'db block gets'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     AND    P2.name = 'consistent gets'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     AND    P3.name = 'physical reads'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. The db_block_buffers parameter in the parameter file determines the size of the buffer cache for the instance. The size of the buffer cache (in bytes) is equal to the value of the db_block_buffers parameter multiplied by the data block size.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. When Oracle performs a full table scan of a large table, the blocks are read into the buffer cache but placed at the least recently used end of the LRU list. This causes the blocks to be aged out quickly, and prevents one large full table scan from wiping out the entire buffer cache.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     SELECT   A.file_name, B.phyrds, B.phyblkrd&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     FROM     SYS.dba_data_files A, v$filestat B&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     WHERE    B.file# = A.file_id&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     ORDER BY A.file_id&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Spotting I/O Intensive SQL Statements: The v$sqlarea dynamic performance view contains one row for each SQL statement currently in the shared SQL area of the SGA for the instance. v$sqlarea shows the first 1000 bytes of each SQL statement, along with various statistics. Following is a query you can use:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     SELECT   executions, buffer_gets, disk_reads, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;              first_load_time, sql_text&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     FROM     v$sqlarea&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     ORDER BY disk_reads&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. No matter what the hit ratio is, if we are not using all of the buffers that have been allocated, there is no advantage in allocating more. In fact, this could slow us down by forcing more swapping at the OS level.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;So we can just check if there are free buffers:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;select count(1) from v$bh where status='free';&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;COUNT(1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;984&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;a href="http://www.dbspecialists.com/presentations/buffercache.html"&gt;http://www.dbspecialists.com/presentations/buffercache.html&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115144128996394195?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115144128996394195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115144128996394195'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/cache-hits-and-cache-misses.html' title='Cache-Hits and Cache-Misses'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115143942805315291</id><published>2006-06-27T13:08:00.000-07:00</published><updated>2006-06-27T13:17:08.066-07:00</updated><title type='text'>Shared Pool</title><content type='html'>&lt;span style="font-family: verdana;font-family:verdana;" &gt;1. The shared pool portion of the SGA contains the library cache, the dictionary cache, buffers for parallel execution messages, and control structures. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;2. The total size of the shared pool is determined by the initialization parameter SHARED_POOL_SIZE. The default value of this parameter is 8MB on 32-bit platforms and 64MB on 64-bit platforms. Increasing the value of this parameter  increases the amount of memory reserved for the shared pool. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;3. Library Cache: The library cache includes the shared SQL areas, private SQL areas (in the case of a shared server configuration), PL/SQL procedures and packages, and control structures such as locks and library cache handles. Shared SQL areas are accessible to all users, so the library cache is contained in the shared pool within the SGA.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;4. Shared SQL Areas and Private SQL Areas: Oracle represents each SQL statement it runs with a shared SQL area and a private SQL area. Oracle recognizes when two users are executing the same SQL statement and reuses the shared SQL area for those users. However, each user must have a separate copy of the statement’s private SQL area. A shared SQL area contains the parse tree and execution plan for a given SQL statement. Oracle saves memory by using one shared SQL area for SQL statements run multiple times, which often happens when many users run the same application.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;5. PL/SQL Program Units and the Shared Pool: Oracle processes PL/SQL program units (procedures, functions, packages, anonymous blocks, and database triggers) much the same way it processes individual SQL statements. Oracle allocates a shared area to hold the parsed, compiled form of a program unit. Oracle allocates a private area to hold values specific to the session that runs the program unit, including local, global, and package variables (also known as package instantiation) and buffers for executing SQL. If more than one user runs the same program unit, then a single, shared area is used by all users, while each user maintains a separate copy of his or her private SQL area, holding values specific to his or her session.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;6. Individual SQL statements contained within a PL/SQL program unit are processed as&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;described in the previous sections. Despite their origins within a PL/SQL program&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;unit, these SQL statements use a shared area to hold their parsed representations and a&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;private area for each session that runs the statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;7. Dictionary Cache: The data dictionary is a collection of database tables and views containing reference information about the database, its structures, and its users. Oracle accesses the data dictionary frequently during SQL statement parsing. This access is essential to the continuing operation of Oracle. The data dictionary is accessed so often by Oracle that two special locations in memory are designated to hold dictionary data. One area is called the data dictionary cache, also known as the row cache because it holds data as rows instead of buffers (which hold entire blocks of data). The other area in memory to hold dictionary data is the library cache. All Oracle user processes share these two caches for access to data dictionary information. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115143942805315291?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115143942805315291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115143942805315291'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/shared-pool.html' title='Shared Pool'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115143889841638847</id><published>2006-06-27T13:07:00.000-07:00</published><updated>2006-06-27T13:08:18.426-07:00</updated><title type='text'>Database Buffer Cache</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. The database buffer cache is the portion of the SGA that holds copies of data blocks read from datafiles. All user processes concurrently connected to the instance, share access to the database buffer cache.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Organization of the Database Buffer Cache: The buffers in the cache are organized in two lists: the write list and the least recently used (LRU) list. The write list holds dirty buffers, which contain data that has been modified but has not yet been written to disk. The LRU list holds free buffers, pinned buffers, and dirty buffers that have not yet been moved to the write list. Free buffers do not contain any useful data and are available for use. Pinned buffers are currently being accessed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. When an Oracle process accesses a buffer, the process moves the buffer to the most recently used (MRU) end of the LRU list. As more buffers are continually moved to the MRU end of the LRU list, dirty buffers age toward the LRU end of the LRU list. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. The first time an Oracle user process requires a particular piece of data, it searches for the data in the database buffer cache. If the process finds the data already in the cache (a cache hit), it can read the data directly from memory. If the process cannot find the data in the cache (a cache miss), it must copy the data block from a datafile on disk into a buffer in the cache before accessing the data. Accessing data through a cache hit is faster than data access through a cache miss. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. Before reading a data block into the cache, the process must first find a free buffer. The process searches the LRU list, starting at the least recently used end of the list. The process searches either until it finds a free buffer or until it has searched the threshold  limit of buffers. If the user process finds a dirty buffer as it searches the LRU list, it moves that buffer to the write list and continues to search. When the process finds a free buffer, it reads the data block from disk into the buffer and moves the buffer to the MRU end of the LRU list.  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;6. If an Oracle user process searches the threshold limit of buffers without finding a free buffer, the process stops searching the LRU list and signals the DBW0 background process to write some of the dirty buffers to disk. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115143889841638847?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115143889841638847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115143889841638847'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/database-buffer-cache.html' title='Database Buffer Cache'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115143404480455925</id><published>2006-06-27T11:38:00.000-07:00</published><updated>2006-06-27T11:47:24.963-07:00</updated><title type='text'>SGA - System Global Area</title><content type='html'>&lt;a style="font-family: verdana;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/4400/2305/1600/OracleMemoryArchitecture.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/4400/2305/320/OracleMemoryArchitecture.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;A system global area (SGA) is a group of shared memory structures that contain data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;and control information for one Oracle database instance. If multiple users are&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;concurrently connected to the same instance, then the data in the instance’s SGA is&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;shared among the users. Consequently, the SGA is sometimes called the shared global&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;area.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;An SGA and Oracle processes constitute an Oracle instance. Oracle automatically&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;allocates memory for an SGA when you start an instance, and the operating system&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;reclaims the memory when you shut down the instance. Each instance has its own&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SGA.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The SGA contains the following data structures:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Database buffer cache&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Redo log buffer&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Shared pool&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Java pool&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. Large pool (optional)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;6. Streams pool&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;7. Data dictionary cache&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Part of the SGA contains general information about the state of the database and the&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;instance, which the background processes need to access; this is called the fixed SGA.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;No user data is stored here. The SGA also includes information communicated&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;between processes, such as locking information.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: Oracle Database Concepts&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115143404480455925?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115143404480455925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115143404480455925'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/sga-system-global-area.html' title='SGA - System Global Area'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115134850287980377</id><published>2006-06-26T11:31:00.000-07:00</published><updated>2006-06-26T12:01:43.003-07:00</updated><title type='text'>Oracle SQL Hints</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. Oracle comes with an optimizer that promises to optimize a query's execution plan. When this optimizer is really doing a good job, no hints should be required at all. 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. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Syntax&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;/*+ hint */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;/*+ hint(argument) */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;/*+ hint(argument-1 argument-2) */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. 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 if alias names are used for table names. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;select /*+ index(emp_alias ix_emp) */ ... from scott.emp emp_alias&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Hints can be categorized as follows:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Hints for Optimization Approaches and Goals,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Hints for Access Paths, Hints for Query Transformations,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Hints for Join Orders,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Hints for Join Operations,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Hints for Parallel Execution,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Additional Hints &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. Hints for Optimization Approaches and Goals&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    5.1 ALL_ROWS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      One of the hints that 'invokes' the Cost based optimizer&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      ALL_ROWS is usually used for batch processing or data warehousing systems.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    5.2 FIRST_ROWS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      One of the hints that 'invokes' the Cost based optimizer&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      FIRST_ROWS is usually used for OLTP systems.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    5.3 CHOOSE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      One of the hints that 'invokes' the Cost based optimizer&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      This hint lets the server choose (between ALL_ROWS and FIRST_ROWS, based on statistics gathered.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    5.4 RULE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      The RULE hint should be considered deprecated as it is dropped from Oracle9i2. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://www.adp-gmbh.ch/ora/sql/hints.html"&gt;http://www.adp-gmbh.ch/ora/sql/hints.html &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115134850287980377?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134850287980377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134850287980377'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/oracle-sql-hints.html' title='Oracle SQL Hints'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115134661160934222</id><published>2006-06-26T11:23:00.000-07:00</published><updated>2006-06-26T11:30:11.613-07:00</updated><title type='text'>Escape characters in SQL</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. Escape quotes&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Use two quotes for every one displayed. Examples:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; SELECT 'Frank''s Oracle site' AS text FROM DUAL;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;TEXT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;--------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Franks's Oracle site&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; SELECT 'A ''quoted'' word.' AS text FROM DUAL;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;TEXT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;----------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;A 'quoted' word.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt; SELECT 'A ''''double quoted'''' word.' AS text FROM DUAL;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;TEXT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;-------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;A ''double quoted'' word.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Escape wildcard characters&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The LIKE keyword allows for string searches. The '_' wild card character is used to match exactly one character, while '%' is used to match zero or more occurrences of any characters. These characters can be escaped in SQL. Examples:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SELECT name FROM emp &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   WHERE id LIKE '%/_%' ESCAPE '/';&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SELECT name FROM emp &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   WHERE id LIKE '%\%%' ESCAPE '\';&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Escape SQL*Plus special characters&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;When using SQL*Plus, the DEFINE setting can be changed to allow &amp;'s (ampersands) to be used in text:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SET DEFINE ~&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SELECT 'Laurel &amp; Hardy' FROM dual;&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://www.orafaq.com/faq/how_does_one_escape_special_characters_when_writing_sql_queries"&gt;http://www.orafaq.com/faq/how_does_one_escape_special_characters_when_writing_sql_queries&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115134661160934222?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134661160934222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134661160934222'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/escape-characters-in-sql.html' title='Escape characters in SQL'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115134605627892424</id><published>2006-06-26T10:15:00.000-07:00</published><updated>2006-06-26T11:20:56.426-07:00</updated><title type='text'>Difference between IN and EXISTS clause</title><content type='html'>&lt;span style="font-family:verdana;"&gt;The two are processed very very differently.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;1. &lt;span style="font-family:courier new;"&gt;Select * from T1 where x in ( select y from T2 )&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;is typically processed as:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;"&gt;select * &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  from t1, ( select distinct y from t2 ) t2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; where t1.x = t2.y;&lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;The subquery is evaluated, distinct'ed, indexed (or hashed or sorted) and then &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;joined to the original table -- typically.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;2. As opposed to &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;select * from t1 where exists ( select null from t2 where y = x )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;That is processed more like:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:courier new;"&gt;   for x in ( select * from t1 )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   loop&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      if ( exists ( select null from t2 where y = x.x )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      then &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;         OUTPUT THE RECORD&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      end if&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   end loop&lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;It always results in a full scan of T1 whereas the first query can make use of &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;an index on T1(x).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;3. So, when is where exists appropriate and in appropriate?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Lets say the result of the subquery&lt;/span&gt;&lt;span style="font-family:verdana;"&gt; &lt;span style="font-family: courier new;"&gt;( select y from T2 )&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;is "huge" and takes a long time.  But the table T1 is relatively small and &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;executing ( select null from t2 where y = x.x ) is very very fast (nice index on &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;t2(y)).  Then the exists will be faster as the time to full scan T1 and do the &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;index probe into T2 could be less then the time to simply full scan T2 to build &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;the subquery we need to distinct on.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Lets say the result of the subquery is small -- then IN is typicaly more &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;appropriate.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;If both the subquery and the outer table are huge -- either might work as well &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;as the other -- depends on the indexes and other factors.  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Source: A wonderful thread at &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:953229842074"&gt;http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:953229842074&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115134605627892424?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134605627892424'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134605627892424'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/difference-between-in-and-exists.html' title='Difference between IN and EXISTS clause'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115134205751005030</id><published>2006-06-26T10:08:00.000-07:00</published><updated>2006-06-26T10:14:17.513-07:00</updated><title type='text'>When does Oracle choose not to use an index</title><content type='html'>&lt;span style="font-family: verdana;"&gt;This problem normally only arises when the query plan is being generated by the Cost Based Optimizer (CBO). The usual cause is because the CBO calculates that executing a Full Table Scan would be faster than accessing the table via the index. Fundamental things that can be checked are:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   1. &lt;span style="font-family: courier new;"&gt;USER_TAB_COLUMNS.NUM_DISTINCT&lt;/span&gt; - This column defines the number of distinct values the column holds.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   2. &lt;span style="font-family: courier new;"&gt;USER_TABLES.NUM_ROWS - If NUM_DISTINCT = NUM_ROWS&lt;/span&gt; then using an index would be preferable to doing a FULL TABLE SCAN. As the NUM_DISTINCT decreases, the cost of using an index increase thereby making the index less desirable.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   3. &lt;span style="font-family: courier new;"&gt;USER_INDEXES.CLUSTERING_FACTOR&lt;/span&gt; - This defines how ordered the rows are in the index. If CLUSTERING_FACTOR approaches the number of blocks in the table, the rows are ordered. If it approaches the number of rows in the table, the rows are randomly ordered. In such a case, it is unlikely that index entries in the same leaf block will point to rows in the same data blocks.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   4. Decrease the &lt;span style="font-family: courier new;"&gt;INIT.ORA&lt;/span&gt; parameter &lt;span style="font-family: courier new;"&gt;DB_FILE_MULTIBLOCK_READ_COUNT&lt;/span&gt; - A higher value will make the cost of a FULL TABLE SCAN cheaper.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Remember that you MUST supply the leading column of an index, for the index to be used (unless you use a FAST FULL SCAN or SKIP SCANNING).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;There are many other factors that affect the cost, but sometimes the above can help to show why an index is not being used by the CBO. If from checking the above you still feel that the query should be using an index, try specifying an index hint. Obtain an explain plan of the query either using TKPROF with TIMED_STATISTICS, so that one can see the CPU utilization, or with AUTOTRACE to see the statistics. Compare this to the explain plan when not using an index. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115134205751005030?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134205751005030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134205751005030'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/when-does-oracle-choose-not-to-use.html' title='When does Oracle choose not to use an index'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115134165514140040</id><published>2006-06-26T10:06:00.000-07:00</published><updated>2006-06-26T10:07:35.146-07:00</updated><title type='text'>Prevent Oracle from using an Index</title><content type='html'>&lt;span style="font-family: verdana;"&gt;In certain cases, one may want to disable the use of a specific, or all indexes for a given query. Here are some examples:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. Adding an expression to the indexed column&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt;select count(*) from t where empno+0=1000;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  COUNT(*)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;         1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Execution Plan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;--------------------------------------------- ----- --------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=3)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   1    0   SORT (AGGREGATE)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   2    1     TABLE ACCESS (FULL) OF 'T' (Cost=2 Card=1 Bytes=3)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Specifying the FULL hint to force full table scan&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt;select /*+ FULL(t) */ * from t where empno=1000;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO GRADE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      1000 Victor     DBA             7839 20-MAY-03      11000          0         10 JUNIOR&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Execution Plan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;--------------------------------------------- ----- --------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=41)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   1    0   TABLE ACCESS (FULL) OF 'T' (Cost=2 Card=1 Bytes=41)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;3. Specifying NO_INDEX hint&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt;select /*+ NO_INDEX(T) */ count(*) from t where empno=1000;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  COUNT(*)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;         1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Execution Plan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;--------------------------------------------- ----- --------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=3)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   1    0   SORT (AGGREGATE)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   2    1     TABLE ACCESS (FULL) OF 'T' (Cost=2 Card=1 Bytes=3)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Using a function over the indexed column&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;SQL&gt;select count(*) from t where to_number(empno)=1000;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;  COUNT(*)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;         1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Execution Plan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;--------------------------------------------- ----- --------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=3)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   1    0   SORT (AGGREGATE)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   2    1     TABLE ACCESS (FULL) OF 'T' (Cost=2 Card=1 Bytes=3) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.orafaq.com/faq/how_does_one_prevent_oracle_from_using_an_index"&gt;http://www.orafaq.com/faq/how_does_one_prevent_oracle_from_using_an_index&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115134165514140040?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134165514140040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134165514140040'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/prevent-oracle-from-using-index.html' title='Prevent Oracle from using an Index'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115134137056689682</id><published>2006-06-26T10:00:00.000-07:00</published><updated>2006-06-26T10:02:50.573-07:00</updated><title type='text'>Oracle: Case Statement</title><content type='html'>&lt;span style="font-family: verdana;"&gt;In Oracle 9i, you can use the case statement within an SQL statement. It has the functionality of an IF-THEN-ELSE statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The syntax for the case statement is:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        CASE expression&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        WHEN condition_1 THEN result_1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        WHEN condition_2 THEN result_2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        ...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        WHEN condition_n THEN result_n&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        ELSE result END&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;expression is the value that you are comparing to the list of conditions. (ie: condition_1, condition_2, ... condition_n)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;condition_1 to condition_n must all be the same datatype. Conditions are evaluated in the order listed. Once a condition is found to be true, the case statement will return the result and not evaluate the conditions any further.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;result_1 to result_n must all be the same datatype. This is the value returned once a condition is found to be true.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Note:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If no condition is found to be true, then the case statement will return the value in the ELSE clause.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If the ELSE clause is omitted and no condition is found to be true, then the case statement will return NULL.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;You can have up to 255 comparisons in a case statement. Each WHEN ... THEN clause is considered 2 comparisons.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;For Example:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;You could use the case statement in an SQL statement as follows:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    select table_name,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    CASE owner&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    WHEN 'SYS' THEN 'The owner is SYS'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    WHEN 'SYSTEM' THEN 'The owner is SYSTEM'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    ELSE 'The owner is another value' END&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    from all_tables;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The above case statement is equivalent to the following IF-THEN-ELSE statement:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    IF owner = 'SYS' THEN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         result := 'The owner is SYS';&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    ELSIF owner = 'SYSTEM' THEN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        result := 'The owner is SYSTEM'';&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    ELSE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        result := 'The owner is another value';&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    END IF;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The case statement will compare each owner value, one by one.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;One thing to note is that the ELSE clause within the case statement is optional. You could have omitted it. Let's take a look at the SQL statement above with the ELSE clause omitted.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Your SQL statement would look as follows:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    select table_name,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    CASE owner&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    WHEN 'SYS' THEN 'The owner is SYS'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    WHEN 'SYSTEM' THEN 'The owner is SYSTEM' END&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    from all_tables;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;With the ELSE clause omitted, if no condition was found to be true, the case statement would return NULL. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115134137056689682?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134137056689682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134137056689682'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/oracle-case-statement.html' title='Oracle: Case Statement'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115134117046038432</id><published>2006-06-26T09:40:00.000-07:00</published><updated>2006-06-26T09:59:30.550-07:00</updated><title type='text'>Database Clusters</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/4400/2305/1600/Clusters.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/4400/2305/320/Clusters.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;1. Clusters are groups of one or more tables physically stored together because they&lt;/span&gt;&lt;span style="font-family: verdana;"&gt; &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;share common columns and are often used together. Because related rows are&lt;/span&gt;&lt;span style="font-family: verdana;"&gt; &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;physically stored together, disk access time improves.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;2. Like indexes, clusters do not affect application design. Whether a table is part of a &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;cluster is transparent to users and to applications. Data stored in a clustered table is &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;accessed by SQL in the same way as data stored in a nonclustered table.&lt;/span&gt;&lt;span style="font-family: verdana;"&gt;  &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;br /&gt;&lt;br /&gt;Eg: the employees and departments table share the &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;department_id column. When you cluster the employees and departments &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;tables, Oracle physically stores all rows for each department from both the &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;employees and departments tables in the same data blocks.&lt;/span&gt;&lt;span style="font-family: verdana;"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;Because clusters store related rows of different tables together in the same data blocks, &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;properly used clusters offers these benefits:&lt;/span&gt;&lt;span style="font-family: verdana;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;* Disk I/O is reduced for joins of clustered tables.&lt;/span&gt;&lt;span style="font-family: verdana;"&gt; &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;&lt;br /&gt;* Access time improves for joins of clustered tables.&lt;/span&gt;&lt;span style="font-family: verdana;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;* In a cluster, a cluster key value is the value of the cluster key columns for a&lt;/span&gt; &lt;span style="font-family: verdana;font-family:verdana;" &gt;particular row. Each cluster key value is stored only once each in the cluster and&lt;/span&gt; &lt;span style="font-family: verdana;font-family:verdana;" &gt;the cluster index, no matter how many rows of different tables contain the value.&lt;/span&gt; &lt;span style="font-family: verdana;font-family:verdana;" &gt;Therefore, less storage is required to store related table and index data in a cluster &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;than is necessary in nonclustered table format.&lt;br /&gt;&lt;br /&gt;For example, in the diagram notice &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;how each cluster key (each department_id) is stored just once for many rows &lt;/span&gt;&lt;span style="font-family: verdana;font-family:verdana;" &gt;that contain the same value in both the employees and departments tables &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115134117046038432?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134117046038432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115134117046038432'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/database-clusters.html' title='Database Clusters'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115133985359362660</id><published>2006-06-26T09:20:00.000-07:00</published><updated>2006-06-26T09:39:52.193-07:00</updated><title type='text'>"WHERE CURRENT OF" in a Cursor</title><content type='html'>&lt;span style="font-family: verdana;font-family:courier new;" &gt;If you plan on updating or deleting records that have been referenced by a Select For Update statement, you can use the Where Current Of statement. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:courier new;" &gt;The syntax for the Where Current Of statement is either:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    UPDATE table_name&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        SET set_clause&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        WHERE CURRENT OF cursor_name;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;OR&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    DELETE FROM table_name&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    WHERE CURRENT OF cursor_name;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:courier new;" &gt;The Where Current Of statement allows you to update or delete the record that was last fetched by the cursor.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; 1) DECLARE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        /* Output variables to hold the result of the query: */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; 2)     a T1.e%TYPE;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; 3)     b T1.f%TYPE;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        /* Cursor declaration: */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; 4)     CURSOR T1Cursor IS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; 5)         SELECT e, f&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; 6)         FROM T1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; 7)         WHERE e &lt;&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; 8)         FOR UPDATE;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; 9) BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;10)     OPEN T1Cursor;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;11)     LOOP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            /* Retrieve each row of the result of the above query into PL/SQL variables: */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;12)         FETCH T1Cursor INTO a, b;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            /* If there are no more rows to fetch, exit the loop: */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;13)         EXIT WHEN T1Cursor%NOTFOUND;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            /* Delete the current tuple: */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;14)         DELETE FROM T1 WHERE CURRENT OF T1Cursor;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;            /* Insert the reverse tuple: */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;15)         INSERT INTO T1 VALUES(b, a);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;16)     END LOOP;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        /* Free cursor used by the query. */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;17)     CLOSE T1Cursor;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;18) END;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;font-family:courier new;" &gt;Source:&lt;/span&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www.techonthenet.com/oracle/cursors/current_of.php"&gt;http://www.techonthenet.com/oracle/cursors/current_of.php&lt;/a&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www-db.stanford.edu/%7Eullman/fcdb/oracle/or-plsql.html"&gt;http://www-db.stanford.edu/~ullman/fcdb/oracle/or-plsql.html&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115133985359362660?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115133985359362660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115133985359362660'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/where-current-of-in-cursor.html' title='&quot;WHERE CURRENT OF&quot; in a Cursor'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115132856698708113</id><published>2006-06-26T06:25:00.000-07:00</published><updated>2006-06-26T06:37:29.213-07:00</updated><title type='text'>Data Concurrency - Preventable Phenomena and Isolation Levels</title><content type='html'>&lt;span style="font-family:verdana;"&gt;Three preventable phenomena in Concurrent Transactions are:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * Dirty reads: A transaction reads data that has been written by another transaction that has not been committed yet.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * Nonrepeatable (fuzzy) reads: A transaction rereads data it has previously read and finds that another committed transaction has modified or deleted the data.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;    * Phantom reads: A transaction re-executes a query returning a set of rows that satisfies a search condition and finds that another committed transaction has inserted additional rows that satisfy the condition.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;SQL92 Isolation Levels: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;-----------------------&lt;br /&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;Isol.Lvl D N P&lt;/span&gt;&lt;br /&gt;-----------------------&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;RD_UNCOM&lt;/span&gt;&lt;span style="font-family:courier new;"&gt; Y Y Y&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;RD_COMMT&lt;/span&gt;&lt;span style="font-family:courier new;"&gt; N Y Y&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;RPT_READ&lt;/span&gt;&lt;span style="font-family:courier new;"&gt; N N Y&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SERLISBL&lt;/span&gt;&lt;span style="font-family:courier new;"&gt; N N N&lt;/span&gt;&lt;br /&gt;-----------------------&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;RD_UNCOM - Read uncommitted&lt;br /&gt;RD_COMMT - &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;Read committed&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;RPT_READ - Repeatable read&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;SERLISBL - Serializable&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;D - &lt;/span&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;Dirty Read&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;N - &lt;/span&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;Nonrepeatable Read&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;P - Phantom Read&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Oracle offers the read committed and serializable isolation levels, as well as a read-only mode that is not part of SQL92. Read committed is the default. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115132856698708113?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132856698708113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132856698708113'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/data-concurrency-preventable-phenomena.html' title='Data Concurrency - Preventable Phenomena and Isolation Levels'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115132773511000879</id><published>2006-06-26T06:14:00.000-07:00</published><updated>2006-06-26T06:15:35.130-07:00</updated><title type='text'>Cursor Variables - REF CURSOR</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. Cursor variables are like pointers to result sets. You use them when you want to perform a query in one subprogram, and process the results in a different subprogram (possibly one written in a different language). &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. A cursor variable has datatype REF CURSOR, and you might see them referred to informally as REF CURSORs.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Unlike an explicit cursor, which always refers to the same query work area, a cursor variable can refer to different work areas. You cannot use a cursor variable where a cursor is expected, or vice versa.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. You use cursor variables to pass query result sets between PL/SQL stored subprograms and various clients. PL/SQL and its clients share a pointer to the query work area in which the result set is stored. For example, an OCI client, Oracle Forms application, and Oracle database server can all refer to the same work area.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. A query work area remains accessible as long as any cursor variable points to it, as you pass the value of a cursor variable from one scope to another. For example, if you pass a host cursor variable to a PL/SQL block embedded in a Pro*C program, the work area to which the cursor variable points remains accessible after the block completes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;6. To create cursor variables, you define a REF CURSOR type, then declare cursor variables of that type. You can define REF CURSOR types in any PL/SQL block, subprogram, or package. In the following example, you declare a REF CURSOR type that represents a result set from the DEPARTMENTS table:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;DECLARE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   TYPE DeptCurTyp IS REF CURSOR RETURN departments%ROWTYPE;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;7. REF CURSOR types can be strong (with a return type) or weak (with no return type).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;7.1 Strong REF CURSOR types are less error prone because the PL/SQL compiler lets you associate a strongly typed cursor variable only with queries that return the right set of columns. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;7.2 Weak REF CURSOR types are more flexible because the compiler lets you associate a weakly typed cursor variable with any query. Because there is no type checking with a weak REF CURSOR, all such types are interchangeable. Instead of creating a new type, you can use the predefined type SYS_REFCURSOR.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;8. Once you define a REF CURSOR type, you can declare cursor variables of that type in any PL/SQL block or subprogram.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;DECLARE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;  -- strong&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   TYPE GenericCurTyp IS REF CURSOR;  -- weak&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   cursor1 EmpCurTyp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   cursor2 GenericCurTyp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   my_cursor SYS_REFCURSOR; -- didn't need to declare a new type above &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115132773511000879?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132773511000879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132773511000879'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/cursor-variables-ref-cursor.html' title='Cursor Variables - REF CURSOR'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115132623358914597</id><published>2006-06-26T05:49:00.000-07:00</published><updated>2006-06-26T05:50:33.603-07:00</updated><title type='text'>Basic Cursor Operations</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Opening a Cursor&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Opening the cursor executes the query and identifies the result set, which consists of all rows that meet the query search criteria. For cursors declared using the FOR UPDATE clause, the OPEN statement also locks those rows.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Fetching with a Cursor&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Unless you use the BULK COLLECT clause (discussed in the next section), the FETCH statement retrieves the rows in the result set one at a time. Each fetch retrieves the current row and advances the cursor to the next row in the result set.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;DECLARE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  my_sal employees.salary%TYPE;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  my_job employees.job_id%TYPE;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  factor INTEGER := 2;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  CURSOR c1 IS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    SELECT factor*salary FROM employees WHERE job_id = my_job;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   OPEN c1;  -- here factor equals 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   LOOP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      FETCH c1 INTO my_sal;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      EXIT WHEN c1%NOTFOUND;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      factor := factor + 1;  -- does not affect FETCH&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   END LOOP;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   CLOSE x1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;END;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Fetching Bulk Data with Cursors&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;DECLARE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  TYPE NumTab IS TABLE OF employees.employee_id%TYPE;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  TYPE NameTab IS TABLE OF employees.last_name%TYPE;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  nums  NumTab;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  names NameTab;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  CURSOR c1 IS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    SELECT employee_id, last_name&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      FROM employees&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      WHERE job_id = 'ST_CLERK';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  OPEN c1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  FETCH c1 BULK COLLECT INTO nums, names;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;-- Here is where you iterate through the elements in the NUMS and&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;-- NAMES collections.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  NULL;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  CLOSE c1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;END;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Closing a Cursor&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The CLOSE statement disables the cursor, and the result set becomes undefined. Once a cursor is closed, you can reopen it, which runs the query again with the latest values of any cursor parameters and variables referenced in the WHERE clause. Any other operation on a closed cursor raises the predefined exception INVALID_CURSOR. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/06_ora.htm"&gt;http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/06_ora.htm&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115132623358914597?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132623358914597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132623358914597'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/basic-cursor-operations.html' title='Basic Cursor Operations'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115132552572551098</id><published>2006-06-26T05:37:00.000-07:00</published><updated>2006-06-26T05:38:45.726-07:00</updated><title type='text'>%ROWTYPE - PLSQL Records</title><content type='html'>&lt;pre style="font-family: verdana;" space="preserve"&gt;DECLARE&lt;br /&gt;   emp_rec emp%ROWTYPE;&lt;br /&gt;BEGIN&lt;br /&gt;  emp_rec.eno := 1500;&lt;br /&gt;  emp_rec.ename := 'Steven Hill';&lt;br /&gt;  emp_rec.sal := '40000';&lt;br /&gt;-- A %ROWTYPE value can fill in all the row fields.&lt;br /&gt;   INSERT INTO emp VALUES emp_rec;&lt;br /&gt;&lt;br /&gt;-- The fields of a %ROWTYPE can completely replace the table columns.&lt;br /&gt;   UPDATE emp SET ROW = emp_rec WHERE eno = 100;&lt;br /&gt;END;&lt;br /&gt;/&lt;/pre&gt;&lt;span style="font-family: verdana;"&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115132552572551098?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132552572551098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132552572551098'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/rowtype-plsql-records.html' title='%ROWTYPE - PLSQL Records'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115132537786416819</id><published>2006-06-26T05:21:00.000-07:00</published><updated>2006-06-26T05:36:17.926-07:00</updated><title type='text'>Implicit Cursor Attributes</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Implicit cursor attributes return information about the execution of an INSERT, UPDATE, DELETE, or SELECT INTO statement. The values of the cursor attributes always refer to the most recently executed SQL statement. Before Oracle opens the SQL cursor, the implicit cursor attributes yield NULL.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Format: SQL%x &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. %FOUND Attribute: Has a DML Statement Changed Rows?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;%FOUND yields TRUE if an INSERT, UPDATE, or DELETE statement affected one or more rows, or a SELECT INTO statement returned one or more rows&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. %ISOPEN Attribute: Always FALSE for Implicit Cursors&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Oracle closes the SQL cursor automatically after executing its associated SQL statement. As a result, %ISOPEN always yields FALSE.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. %NOTFOUND Attribute: Has a DML Statement Failed to Change Rows?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;%NOTFOUND is the logical opposite of %FOUND&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. %ROWCOUNT Attribute: How Many Rows Affected So Far?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;%ROWCOUNT yields the number of rows affected by an INSERT, UPDATE, or DELETE statement, or returned by a SELECT INTO statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Exception-1: If a SELECT INTO statement returns more than one row, PL/SQL raises the predefined exception TOO_MANY_ROWS and %ROWCOUNT yields 1, not the actual number of rows that satisfy the query.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Exception-2: The %NOTFOUND attribute is not useful in combination with the SELECT INTO statement:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;* If a SELECT INTO statement fails to return a row, PL/SQL raises the predefined exception NO_DATA_FOUND immediately, interrupting the flow of control before you can check %NOTFOUND.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;* A SELECT INTO statement that calls a SQL aggregate function always returns a value or a null. After such a statement, the %NOTFOUND attribute is always FALSE, so checking it is unnecessary.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. %BULK_ROWCOUNT Attribute: Counting Rows Affected by FORALL &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;CREATE TABLE emp2 AS SELECT * FROM employees;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;DECLARE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   TYPE NumList IS TABLE OF NUMBER;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   depts NumList := NumList(30, 50, 60);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   FORALL j IN depts.FIRST..depts.LAST&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      DELETE FROM emp2 WHERE department_id = depts(j);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;-- How many rows were affected by each DELETE statement?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   FOR i IN depts.FIRST..depts.LAST&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   LOOP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      dbms_output.put_line('Iteration #' || i || ' deleted ' ||&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         SQL%BULK_ROWCOUNT(i) || ' rows.');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   END LOOP;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;END;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;DROP TABLE emp2; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/06_ora.htm"&gt;http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/06_ora.htm&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115132537786416819?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132537786416819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132537786416819'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/implicit-cursor-attributes.html' title='Implicit Cursor Attributes'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115132124704832962</id><published>2006-06-26T04:26:00.000-07:00</published><updated>2006-06-26T04:27:27.056-07:00</updated><title type='text'>Basic Query Patterns with Examples</title><content type='html'>&lt;a style="font-family: verdana;" href="http://dev.fyicenter.com/faq/oracle/oracle_sql_select_query_statements.html"&gt;http://dev.fyicenter.com/faq/oracle/oracle_sql_select_query_statements.html&lt;/a&gt;&lt;span style="font-family: verdana;"&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115132124704832962?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132124704832962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132124704832962'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/basic-query-patterns-with-examples.html' title='Basic Query Patterns with Examples'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115132020843944940</id><published>2006-06-26T04:09:00.000-07:00</published><updated>2006-06-26T04:10:08.443-07:00</updated><title type='text'>First/Last records in a table – in insertion order</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Since there is no inherent way for you to figure out the order the rows were put into a table, this one is a little trickier. The only way you can positively indicate the order the rows were inserted into the table is if you explicitly mark each record. Sometimes this may be a “DATE_INSERTED” field or it may be some other field that indicates order. In my example, I have created a BEFORE INSERT trigger to populate the Primary Key (x) with a value from a sequence:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;create trigger xyz_bi&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;before insert&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;on xyz&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;for each row&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;declare&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   pkval number;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;begin&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   select xyz_id.nextval into pkval from dual;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   :new.x := pkval;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;end;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Therefore, I know my rows were inserted in the order according to X. I can then use my PK value to find out the last 10 rows inserted by:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SQL&gt; select * from (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  2     select * from xyz&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  3     order by x desc&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  4     )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  5  where rownum &lt;&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  6  /&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         X          Y Z&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;---------- ---------- -------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       156         30 09/15/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       155         29 09/24/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       154         28 09/23/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       153         27 09/22/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       152         26 09/21/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       151         25 09/20/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       150         24 09/19/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       149         23 09/18/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       148         22 09/17/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       147         21 09/16/2005 14:48:42&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;10 rows selected.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://marist89.blogspot.com/2005/09/top-n.html"&gt;&lt;span style="font-family: verdana;"&gt;Source: http://marist89.blogspot.com/2005/09/top-n.html &lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115132020843944940?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132020843944940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115132020843944940'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/firstlast-records-in-table-in.html' title='First/Last records in a table – in insertion order'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131958971370362</id><published>2006-06-26T03:58:00.000-07:00</published><updated>2006-06-26T03:59:49.726-07:00</updated><title type='text'>Top-N Queries using RANK() function</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. For a top-N query you can use two ranking functions: RANK and DENSE_RANK. Both allow you to rank items in a group—for example, finding the top-five employees by salary, which is exactly what we need to achieve.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The difference between RANK() and DENSE_RANK() is that RANK() leaves gaps in the ranking sequence when there are ties. In our case, Scott and Ford tie for second place with a $3,000 salary; Jones' $2,975 salary brings him in third place using DENSE_RANK() but only fourth place using RANK():&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SELECT Empno, Ename, Job, Mgr, Sal,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   RANK() OVER&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      (ORDER BY SAL Desc NULLS LAST) AS Rank,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   DENSE_RANK() OVER&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      (ORDER BY SAL Desc NULLS LAST) AS Drank&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   FROM Emp&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   ORDER BY SAL Desc NULLS LAST;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. The NULLS FIRST | NULLS LAST clause determines the position of rows with NULL values in the ordered query.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If the sequence is in descending order, then NULLS LAST implies that NULL values are smaller than non-NULL ones and rows with NULLs will appear at the bottom of the list. If the NULLS FIRST | NULLS LAST clause is omitted, then NULL values are considered larger than any other values and their ordering position depends on the ASC | DESC arguments.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If the ordering sequence is ascending (ASC), then rows with NULLs will appear last; if the sequence is descending (DESC), then rows with NULLs will appear first. NULLs are considered equal to other NULLs and, therefore, the order in which rows with NULLs are presented is nondeterministic.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Using RANK() to Obtain a Top-N Query&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;To obtain a top-N query, use RANK() in a subquery and then apply a filter condition outside the subquery:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SELECT Empno, Ename, Job, Mgr, Hiredate, Sal&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   FROM&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   (SELECT Empno, Ename, Job, Mgr, Hiredate, Sal,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      RANK() OVER&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         (ORDER BY SAL Desc NULLS LAST) AS Emp_Rank&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      FROM Emp&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      ORDER BY SAL Desc NULLS LAST)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   WHERE Emp_Rank &lt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Ranking functions can be used to operate within groups, too—that is, the rank value gets reset whenever the group changes. This is achieved with a PARTION BY subclause. Here is the syntax to retrieve the top employee by salary per manager group:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SELECT Empno, Ename, Job, Mgr, Hiredate, Sal&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   FROM&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   (SELECT Empno, Ename, Job, Mgr, Hiredate, Sal,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      RANK() OVER&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         (PARTITION BY MGR ORDER BY MGR, SAL DESC NULLS LAST) AS Emp_Rank&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      FROM Emp&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      ORDER BY MGR, SAL DESC NULLS LAST)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   WHERE Emp_Rank = 1;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.devx.com/gethelpon/10MinuteSolution/16608/0/page/4"&gt;&lt;span style="font-family: verdana;"&gt;http://www.devx.com/gethelpon/10MinuteSolution/16608/0/page/4&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.devx.com/gethelpon/10MinuteSolution/16608/0/page/5"&gt;&lt;span style="font-family: verdana;"&gt;http://www.devx.com/gethelpon/10MinuteSolution/16608/0/page/5&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131958971370362?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131958971370362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131958971370362'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/top-n-queries-using-rank-function.html' title='Top-N Queries using RANK() function'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131865744671962</id><published>2006-06-26T03:43:00.000-07:00</published><updated>2006-06-26T03:44:17.456-07:00</updated><title type='text'>PseudoColumns in Oracle</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Pseudocolumns&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;A pseudocolumn behaves like a table column, but is not actually stored in the table. You can select from pseudocolumns, but you cannot insert, update, or delete their values.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. CURRVAL and NEXTVAL&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;schema.sequence.CURRVAL: returns the current value of a sequence&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;schema.sequence.NEXTVAL: increments the sequence and returns the next value&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;(Over a DB Link &gt;&gt;  schema.sequence.CURRVAL@dblink and schema.sequence.NEXTVAL@dblink)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. LEVEL&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;For each row returned by a hierarchical query, the LEVEL pseudocolumn returns 1 for a root row, 2 for a child of a root, and so on.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SELECT v.employee_id, v.last_name, v.lev &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   FROM &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      (SELECT employee_id, last_name, LEVEL lev &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      FROM employees v&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      START WITH employee_id = 100 &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      CONNECT BY PRIOR employee_id = manager_id) v &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   WHERE (v.employee_id, v.lev) IN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;      (SELECT employee_id, 2 FROM employees); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. ROWID&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;For each row in the database, the ROWID pseudocolumn returns a row's address. Rowid values contain information necessary to locate a row.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;# They are the fastest way to access a single row.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;# They can show you how a table's rows are stored.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;# They are unique identifiers for rows in a table.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;You should not use ROWID as a table's primary key. If you delete and reinsert a row with the Import and Export utilities, for example, then its rowid may change. If you delete a row, then Oracle may reassign its rowid to a new row inserted later.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. ROWNUM&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;For each row returned by a query, the ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table or set of joined rows. The first row selected has a ROWNUM of 1, the second has 2, and so on. You can use ROWNUM to limit the number of rows returned by a query, as in this example:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SELECT * FROM employees WHERE ROWNUM &lt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;If you embed the ORDER BY clause in a subquery and place the ROWNUM condition in the top-level query, then you can force the ROWNUM condition to be applied after the ordering of the rows. For example, the following query returns the 10 smallest employee numbers. This is sometimes referred to as a "top-N query":&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SELECT * FROM&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   (SELECT * FROM employees ORDER BY employee_id)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;   WHERE ROWNUM &lt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. XMLDATA&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Oracle stores XMLType data either in LOB or object-relational columns, based on XMLSchema information and how you specify the storage clause. The XMLDATA pseudocolumn lets you access the underlying LOB or object relational column to specify additional storage clause parameters, constraints, indexes, and so forth.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Source: &lt;/span&gt;&lt;a style="font-family: verdana;" href="http://www.utexas.edu/its/unix/reference/oracledocs/v92/B10501_01/server.920/a96540/sql_elements6a.htm"&gt;http://www.utexas.edu/its/unix/reference/oracledocs/v92/B10501_01/server.920/a96540/sql_elements6a.htm&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131865744671962?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131865744671962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131865744671962'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/pseudocolumns-in-oracle.html' title='PseudoColumns in Oracle'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131747654879494</id><published>2006-06-26T03:23:00.000-07:00</published><updated>2006-06-26T03:24:36.556-07:00</updated><title type='text'>Details on Functions</title><content type='html'>1. A function is a subprogram that can take parameters and return a single value.&lt;br /&gt;&lt;br /&gt;2. Inside a function, an IN parameter acts like a constant; you cannot assign it a value. An OUT parameter acts like a local variable; you can change its value and reference the value in any way. An IN OUT parameter acts like an initialized variable; you can assign it a value, which can be assigned to another variable.&lt;br /&gt;&lt;br /&gt;3. Avoid using the OUT and IN OUT modes with functions. The purpose of a function is to take zero or more parameters and return a single value. Functions should be free from side effects, which change the values of variables not local to the subprogram.&lt;br /&gt;&lt;br /&gt;4. NOCOPY&lt;br /&gt;A compiler hint (not directive) that allows the PL/SQL compiler to pass OUT and IN OUT parameters by reference instead of by value (the default). The function can run faster, because it does not have to make temporary copies of these parameters, but the results can be different if the function ends with an unhandled exception.&lt;br /&gt;&lt;br /&gt;5. PARALLEL_ENABLE&lt;br /&gt;Declares that a stored function can be used safely in the slave sessions of parallel DML evaluations. The state of a main (logon) session is never shared with slave sessions. Each slave session has its own state, which is initialized when the session begins. The function result should not depend on the state of session (static) variables. Otherwise, results might vary across sessions.&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/13_elems022.htm"&gt;www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/13_elems022.htm&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131747654879494?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131747654879494'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131747654879494'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/details-on-functions.html' title='Details on Functions'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131666100582346</id><published>2006-06-26T03:03:00.000-07:00</published><updated>2006-06-26T03:11:01.006-07:00</updated><title type='text'>OCI -Vs- Precompiler</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. Oracle Call Interface&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The Oracle Call Interface (OCI) is a set of low-level APIs (Application Programming Interface Calls) used to interact with Oracle databases. It allows one to use operations like logon, execute, parse, fetch, etc. OCI programs are normally written in C or C++, although they can be written in almost any programing language.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Unlike with the Oracle Precompilers (like Pro*C and Pro*COBOL), OCI programs are not precompiled&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1.1 OCI is superior to Pro*C in the following ways:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Performance is much better with OCI&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Reduced code size&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Direct access to built-in functions (No intermediate files or substitutions).&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Piecewise Operation on LONG fields (All LONG field problems are solved)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * In Pro*C one cannot dynamically allocate memory to be used as bind variables&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * You cannot control the Pro*C precompiler to provide better and more compilable C-code.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1.2 Common problems with OCI:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * OCI code is difficult to write and to maintain &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Precompiler&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;A precompiler is a tool that allows programmers to embed SQL statements in high-level source programs like C, C++, COBOL, etc. The precompiler accepts the source program as input, translates the embedded SQL statements into standard Oracle runtime library calls, and generates a modified source program that one can compile, link, and execute in the usual way. Examples are the Pro*C Precompiler for C, Pro*Cobol for Cobol, SQLJ for Java, etc.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Sources:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.orafaq.com/faqoci.htm"&gt;&lt;span style="font-family: verdana;"&gt;http://www.orafaq.com/faqoci.htm&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;&lt;a href="http://www.orafaq.com/faq/precompilers"&gt;http://www.orafaq.com/faq/precompilers&lt;/a&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131666100582346?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131666100582346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131666100582346'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/oci-vs-precompiler.html' title='OCI -Vs- Precompiler'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131594021892169</id><published>2006-06-26T02:58:00.000-07:00</published><updated>2006-06-26T02:59:00.223-07:00</updated><title type='text'>Autonomous Transactions</title><content type='html'>&lt;span style="font-family: verdana;"&gt;Autonomous Transaction is a feature of oracle 8i which  maintains  the state of its transactions and save  it ,  to affect with the commit or rollback  of the surrounding transactions.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Here is the simple example to understand this :-&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SQL :&gt; declare&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  2   Procedure InsertInTest_Table_B&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  3    is&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  4    BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  5     INSERT into Test_Table_B(x) values (1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  6     Commit;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  7    END ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  8    BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  9      INSERT INTO Test_Table_A(x) values (123);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; 10      InsertInTest_Table_B;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; 11      Rollback;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; 12    END;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; 13  /&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;PL/SQL procedure successfully completed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SQL :&gt; Select * from Test_Table_A;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         X&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;       123&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SQL :&gt; Select * from Test_Table_B;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         X&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; Notice in above pl/sql  COMMIT at line no 6 , commits the transaction at  line-no 5 and  line-no 9. The Rollback at line-no 11 actually did nothing.  Commit/ROLLBACK at nested transactions will commit/rollback all  other DML transaction before that. PRAGMA AUTONOMOUS_TRANSACTION override this behavior.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Let us the see the following example with PRAGMA AUTONOMOUS_TRANSACTION.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SQL :&gt; declare&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  2     Procedure InsertInTest_Table_B&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  3     is&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  4     PRAGMA AUTONOMOUS_TRANSACTION;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  5       BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  6         INSERT into Test_Table_B(x) values (1); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  7         Commit;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  8       END ;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  9       BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; 10        INSERT INTO Test_Table_A(x) values (123);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; 11        InsertInTest_Table_B;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; 12        Rollback;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; 13       END;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; 14     /&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;PL/SQL procedure successfully completed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SQL :&gt; Select * from Test_Table_A;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;no rows selected&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;SQL :&gt; Select * from Test_Table_B;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         X&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;----------&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt; With PRAGMA AUTONOMOUS_TRANSACTION , the transaction state maintained independently . Commit/Rollback of nested transaction will no effect the other transaction. It is advisable to increase the value of  TRANSACTIONS parameter in the INIT parameter file to allow for the extra concurrent transaction . &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www.samoratech.com/PLSQL/TIPautonomousTrans.htm"&gt;Source: http://www.samoratech.com/PLSQL/TIPautonomousTrans.htm&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131594021892169?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131594021892169'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131594021892169'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/autonomous-transactions.html' title='Autonomous Transactions'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131567917671613</id><published>2006-06-26T02:53:00.000-07:00</published><updated>2006-06-26T02:54:39.183-07:00</updated><title type='text'>UTL_FILE</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. The Oracle supplied package UTL_FILE can be used to read and write files that are located on the server. It cannot be used to access files locally, that is on the computer where the client is running. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. The following two procedures show how to use utl_file to write to and read from a file using PL/SQL. It doesn't do very much let alone something useful, but it can be extended.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;In order to use it, make sure the utl_file_dir paramter is set:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. select value from v$parameter where name = 'utl_file_dir';&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The value returned is actually the path that you must use in the arguments to utl_file_test_read and utl_file_test_write. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. utl_file_test_write writes two lines into the file specified with the parameters path and filename.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;create or replace procedure utl_file_test_write (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  path       in varchar2,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  filename   in varchar2,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  firstline  in varchar2, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  secondline in varchar2)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;is&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    output_file  utl_file.file_type;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;begin&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    output_file := utl_file.fopen (path,filename, 'W');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    utl_file.put_line (output_file, firstline);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    utl_file.put_line (output_file, secondline);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    utl_file.fclose(output_file);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  --exception&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  --  when others then null;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;end;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. utl_file_test_read reads two lines from the file specified with the parameters path and filename and prints them using dbms_output.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;create or replace procedure utl_file_test_read (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  path       in varchar2,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  filename   in varchar2)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;is&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  input_file   utl_file.file_type;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  input_buffer varchar2(4000);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;begin&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  input_file := utl_file.fopen (path,filename, 'R');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  utl_file.get_line (input_file, input_buffer);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  dbms_output.put_line(input_buffer);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  utl_file.get_line (input_file, input_buffer);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  dbms_output.put_line(input_buffer);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  utl_file.fclose(input_file);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  --exception&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  -- when others then null;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;end;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;6. Creating and writing to a file:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;begin&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  utl_file_test_write (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    '/tmp',&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    'utl_file_test',&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    'first line',&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    'second line'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;end;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;7. Now, reading from the file:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;set serveroutput on size 1000000&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;begin&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  utl_file_test_read('/tmp','utl_file_test');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;end;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Also check in your utl_file_dir that the file was created.  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www.adp-gmbh.ch/ora/plsql/utl_file.html"&gt;Source: http://www.adp-gmbh.ch/ora/plsql/utl_file.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131567917671613?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131567917671613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131567917671613'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/utlfile.html' title='UTL_FILE'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131524297538532</id><published>2006-06-26T02:43:00.000-07:00</published><updated>2006-06-26T02:47:22.976-07:00</updated><title type='text'>Built-in functions/operators for manipulating strings</title><content type='html'>&lt;span style="font-family: verdana;"&gt;The most useful ones are LENGTH, SUBSTR, INSTR, and ||:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * LENGTH(str) returns the length of str in characters.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * SUBSTR(str,m,n) returns a portion of str, beginning at character m, n characters long. If n is omitted, all characters to the end of str will be returned.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * INSTR(str1,str2,n,m) searches str1 beginning with its n-th character for the m-th occurrence of str2 and returns the position of the character in str1 that is the first character of this occurrence.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * str1 || str2 returns the concatenation of str1 and str2.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;The example below shows how to convert a string name of the format 'last, first' into the format 'first last':&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        SUBSTR(name, INSTR(name,',',1,1)+2)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    ||  ' '&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    ||  SUBSTR(name, 1, INSTR(name,',',1,1)-1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;For case-insensitive comparisons, first convert both strings to all upper case using Oracle's built-in function upper() (or all lower case using lower()). &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www-db.stanford.edu/%7Eullman/fcdb/oracle/or-faq.html#string"&gt;Source: http://www-db.stanford.edu/%7Eullman/fcdb/oracle/or-faq.html#string&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131524297538532?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131524297538532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131524297538532'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/built-in-functionsoperators-for.html' title='Built-in functions/operators for manipulating strings'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131486014872203</id><published>2006-06-26T02:39:00.000-07:00</published><updated>2006-06-26T02:41:00.163-07:00</updated><title type='text'>Object-Relational Features of Oracle</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. Defining Types&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     CREATE TYPE PointType AS OBJECT (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         x NUMBER,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         y NUMBER&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     );&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;An object type can be used like any other type in further declarations of object-types or table-types. For instance, we might define a line type by:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     CREATE TYPE LineType AS OBJECT (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         end1 PointType,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         end2 PointType&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     );&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     CREATE TABLE Lines (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         lineID NUMBER,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         line   LineType&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     );&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Constructing Object Values&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     INSERT INTO Lines&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         VALUES(27, LineType(&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;                         PointType(0.0, 0.0),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;                         PointType(3.0, 4.0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;                    )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         );&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. A type declaration can also include methods that are defined on values of that type. The method is declared by MEMBER FUNCTION or MEMBER PROCEDURE in the CREATE TYPE statement, and the code for the function itself (the definition of the method) is in a separate CREATE TYPE BODY statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Methods have available a special tuple variable SELF, which refers to the ``current'' tuple. If SELF is used in the definition of the method, then the context must be such that a particular tuple is referred to.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     CREATE TYPE LineType AS OBJECT (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         end1 PointType,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         end2 PointType,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         MEMBER FUNCTION length(scale IN NUMBER) RETURN NUMBER,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         PRAGMA RESTRICT_REFERENCES(length, WNDS)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     );&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Note the ``pragma'' that says the length method will not modify the database (WNDS = write no database state). This clause is necessary if we are to use length in queries.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     CREATE TYPE BODY LineType AS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         MEMBER FUNCTION length(scale NUMBER) RETURN NUMBER IS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;              BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;                  RETURN scale *&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;                      SQRT((SELF.end1.x-SELF.end2.x)*(SELF.end1.x-SELF.end2.x) +&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;                           (SELF.end1.y-SELF.end2.y)*(SELF.end1.y-SELF.end2.y)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;                      );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;              END;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     END;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     /&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;  Notice that the mode of the argument is not given here. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. Queries to Relations That Involve User-Defined Types&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    SELECT lineID, ll.line.length(2.0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     FROM Lines ll;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Note that in order to access fields of an object, we have to start with an alias of a relation name. While lineID, being a top-level attribute of relation LInes, can be referred to normally, in order to get into the attribute line, we need to give relation Lines an alias (we chose ll) and use it to start all paths to the desired subobjects.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Dropping the ``ll.'' or replacing it by ``Lines.'' doesn't work.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * Notice also the use of a method in a query. Since line is an attribute of type LineType, one can apply to it the methods of that type, using the dot notation shown. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. Nested Tables&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;A more powerful use of object types in Oracle is the fact that the type of a column can be a table-type. That is, the value of an attribute in one tuple can be an entire relation.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;     CREATE TABLE Polygons (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         name   VARCHAR2(20),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         points PolygonType)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;         NESTED TABLE points STORE AS PointsTable;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www-db.stanford.edu/%7Eullman/fcdb/oracle/or-objects.html"&gt;Source: http://www-db.stanford.edu/%7Eullman/fcdb/oracle/or-objects.html&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131486014872203?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131486014872203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131486014872203'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/object-relational-features-of-oracle.html' title='Object-Relational Features of Oracle'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131352854630224</id><published>2006-06-26T02:16:00.000-07:00</published><updated>2006-06-26T02:18:48.546-07:00</updated><title type='text'>Pro*C</title><content type='html'>&lt;span style="font-family: verdana;"&gt; Embedded SQL is a method of combining the computing power of a high-level language like C/C++ and the database manipulation capabilities of SQL. It allows you to execute any SQL statement from an application program. Oracle's embedded SQL environment is called Pro*C. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;A Pro*C program is compiled in two steps.  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;1. First, the Pro*C &lt;/span&gt;&lt;i style="font-family: verdana;"&gt;precompiler&lt;/i&gt;&lt;span style="font-family: verdana;"&gt; recognizes the SQL statements embedded in the program, and replaces them with appropriate calls to the functions in the SQL runtime library. The output is pure C/C++ code with all the pure C/C++ portions intact. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Then, a regular C/C++ compiler is used to compile the code and produces the executable. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www-db.stanford.edu/%7Eullman/fcdb/oracle/or-proc.html"&gt;Source: http://www-db.stanford.edu/~ullman/fcdb/oracle/or-proc.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131352854630224?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131352854630224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131352854630224'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/proc.html' title='Pro*C'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-30275011.post-115131287758592851</id><published>2006-06-26T02:01:00.000-07:00</published><updated>2006-06-26T02:07:57.593-07:00</updated><title type='text'>Oracle Constraints and Triggers</title><content type='html'>&lt;span style="font-family: verdana;"&gt;1. Constraints are declaractions of conditions about the database that must remain true. These include attributed-based, tuple-based, key, and referential integrity constraints. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;2. Triggers are a special PL/SQL construct similar to procedures. However, a procedure is executed explicitly from another block via a procedure call, while a trigger is executed implicitly whenever the triggering event happens. The triggering event is either a INSERT, DELETE, or UPDATE command. The timing can be either BEFORE or AFTER. The trigger can be either row-level or statement-level, where the former fires once for each row affected by the triggering statement and the latter fires once for the whole statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;3. Deferring Constraint Checking&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;4. To view a list of all defined triggers, use:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;select trigger_name from user_triggers; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;5. drop trigger &lt;trigger_name&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;6. alter trigger &lt;trigger_name&gt; {disable|enable};&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;7. Aborting Triggers with Error&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;create table Person (age int);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;CREATE TRIGGER PersonCheckAge&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;AFTER INSERT OR UPDATE OF age ON Person&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;FOR EACH ROW&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    IF (:new.age &lt;&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;        RAISE_APPLICATION_ERROR(-20000, 'no negative age allowed');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    END IF;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;END;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;8. Mutating Table Errors&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;Sometimes you may find that Oracle reports a "mutating table error" when your trigger executes. This happens when the trigger is querying or modifying a "mutating table", which is either the table whose modification activated the trigger, or a table that might need to be updated because of a foreign key constraint with a CASCADE policy. To avoid mutating table errors:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * A row-level trigger must not query or modify a mutating table. (Of course, NEW and OLD still can be accessed by the trigger.)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: verdana;"&gt;    * A statement-level trigger must not query or modify a mutating table if the trigger is fired as the result of a CASCADE delete.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a style="font-family: verdana;" href="http://www-db.stanford.edu/%7Eullman/fcdb/oracle/or-triggers.html"&gt;Source : http://www-db.stanford.edu/~ullman/fcdb/oracle/or-triggers.html &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30275011-115131287758592851?l=orabase.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131287758592851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30275011/posts/default/115131287758592851'/><link rel='alternate' type='text/html' href='http://orabase.blogspot.com/2006/06/oracle-constraints-and-triggers.html' title='Oracle Constraints and Triggers'/><author><name>AJ</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://3.bp.blogspot.com/_z_dN2G0XfAw/Ss_9RA9dbbI/AAAAAAAAAYE/Eul7v0yLDuE/S220/nine.PNG'/></author></entry></feed>
