<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pure Performance Inc &#187; Oracle</title>
	<atom:link href="http://www.pure-performance.com/tag/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pure-performance.com</link>
	<description>Web and PeopleSoft Consulting</description>
	<lastBuildDate>Fri, 02 Apr 2010 01:59:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Removing duplicate rows (SQL)</title>
		<link>http://www.pure-performance.com/2009/02/removing-duplicate-rows-sql/</link>
		<comments>http://www.pure-performance.com/2009/02/removing-duplicate-rows-sql/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 15:34:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[duplicate rows]]></category>

		<guid isPermaLink="false">http://pure-performance.com/?p=50</guid>
		<description><![CDATA[At least once in your career you will have to deal with duplicate rows causing havic on you application.  This post will help you get through that delema.  I have Oracle and MySql examples below.]]></description>
			<content:encoded><![CDATA[<div style="float:right;display:inline;margin:0px 0px 0px 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-1316867219585554";
/* 234x60, ppi */
google_ad_slot = "4700353166";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><img class="alignleft size-full wp-image-58" title="Oracle MySql Duplicates" src="http://pure-performance.com/wp-content/uploads/2009/02/oraclemysqlo.jpg" alt="Oracle MySql Duplicates" width="100" height="78" />At least once in your career you will have to deal with duplicate rows causing havoc on you application.  This post will help you get through that dilema.  I have Oracle and MySql examples below.</p>
<h2>ORACLE Specific</h2>
<p>With Oracle with have the luxury of <a title="Rowid Defined" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns008.htm" target="_blank">ROWID </a>which uniquely identifies a row in an Oracle table. We will use this pseudo column to remove the duplicates.</p>
<h4>Simple Method</h4>
<p>This is the simplest method which removes the latest duplicate row added. If you want to remove the earliest you need to change  MAX to MIN and replace &#8220;less than&#8221;(&lt;) with &#8220;greater than&#8221;(&gt;).</p>
<blockquote><p>DELETE FROM [TABLE] A<br />
WHERE ROWID &lt;  ( SELECT max(ROWID)<br />
FROM [TABLE] B<br />
WHERE A.[PRIMARY KEY FIELDS] = B.[PRIMARY KEY FIELDS]);</p></blockquote>
<h4>Another method with constraints</h4>
<p>This is another method you can use if you have constraints. This method uses the Oracle function &#8220;<a title="Exists Oracle function" href="http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/conditions009.htm#sthref943" target="_blank">Exists</a>&#8221; which checks for the existence in a sub-query.</p>
<blockquote><p>DELETE FROM [TABLE] A<br />
WHERE CONTRAINT = [VARIABLE]<br />
AND EXISTS ( SELECT &#8216;X&#8217;<br />
FROM [TABLE] B<br />
WHERE A.[PRIMARY KEY FIELDS] = B.[PRIMARY KEY FIELDS]<br />
AND A.ROWID &lt; B.ROWID);</p></blockquote>
<h2>MYSQL <small> (These would also work in Oracle )</small></h2>
<p>With MySQL  we do not have the tools that Oracle has to easily find the duplicates. But most MySql tables use an auto-increment ID field that helps us to identify the duplicates.</p>
<h4>Simple Method</h4>
<p>As with the Oracle method use the &#8220;greater than&#8221; sign to to keep the earliest row entered. We can change this  to pull the latest  by replacing &#8220;greater than&#8221; with &#8220;less than&#8221;.</p>
<blockquote><p>DELETE A FROM [TABLE] as A, [TABLE] as B<br />
WHERE A.[UNIQUE FIELD(S)] = B.[UNIQUE FIELD(S)]<br />
AND A.ID &gt; B.ID;</p></blockquote>
<h4>Without the ID field</h4>
<p>Now it gets complicated in MySQL, we need to create a table with an unique ID then remove the duplicates. Once the dups have been remove  then  we can put the data back onto the original table.</p>
<blockquote><p><em>Drop the dups table if it exists.</em></p>
<p>DROP TABLE IF EXISTS [TABLE]_dups;</p>
<p><em>Create the dups table.  This table will be the base table(table with dups) with the ID added.</em></p>
<p>CREATE TABLE [TABLE]_dups (<br />
id INT(11) default NULL auto_increment,<br />
[ALL TABLE COLUMNS],<br />
PRIMARY KEY (id)<br />
);</p>
<p><em>Insert into the dups table from the base table.</em></p>
<p>INSERT INTO [TABLE]_dups<br />
SELECT NULL,[UNIQUE FIELD(S)]<br />
FROM [TABLE];</p>
<p><em>Delete the dups using the SQL we used in the prior example</em></p>
<p>DELETE A FROM [TABLE]_dups as A, [TABLE]_dups as B<br />
WHERE A.[UNIQUE FIELD(S)] = B.[UNIQUE FIELD(S)]<br />
AND A.ID &lt; B.ID;</p>
<p><em>Delete the Base table</em></p>
<p>DELETE FROM [TABLE];</p>
<p><em>Insert into the base table from the dups table.</em></p>
<p>INSERT INTO [TABLE]<br />
SELECT [all columns less the ID field]<br />
FROM [TABLE]_dups;</p>
<p><em>Remove the dups table</em></p>
<p>DROP TABLE [TABLE]_dups;</p></blockquote>
<p>I hope this posts help you when you run into this problem&#8230; and we all run into this problem.</p>
<div style="text-align:center;width:100%;"><div style="margin:0px 0px 0px 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-1316867219585554";
/* 728x90, ppi */
google_ad_slot = "8229743782";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.pure-performance.com/2009/02/removing-duplicate-rows-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Searching Oracle (Database/PLSQL)</title>
		<link>http://www.pure-performance.com/2009/01/searching-oracle-databaseplsql/</link>
		<comments>http://www.pure-performance.com/2009/01/searching-oracle-databaseplsql/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 14:46:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[database search]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://pure-performance.com/?p=16</guid>
		<description><![CDATA[During development things always change.  Column names change, columns may be added or removed from tables and so on.  When this happens, you need to go back to your PL/SQL programs and change the code. In some cases, you can just recompile the package or procedure to find the problems caused.   But that doesn't always catch everything, especially when you have dynamic SQL.  So you should always run a PL/SQL search to find the column or text that has changed.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-31" title="Oracle Search" src="http://pure-performance.com/wp-content/uploads/2009/01/orasearch.jpg" alt="Oracle Search" width="117" height="114" /><br />
<h2>PL/SQL Search</h2>
<p>During development things always change.  Column names change, columns may be added or removed from tables and so on.  When this happens, you need to go back to your PL/SQL programs and change the code. In some cases, you can just recompile the package or procedure to find the problems caused.   But that doesn&#8217;t always catch everything, especially when you have dynamic SQL.  So you should always run a PL/SQL search to find the column or text that has changed.</p>
<p>To do this, we use the  Oracle Data dictionary view  XXX_SOURCE (USER_SOURCE,  ALL_SOURCE,  or DBA_SOURCE depending on your access ) .  With USER_SOURCE you do not specify the owner since it only returns the source for the schema you&#8217;re logged into.</p>
<p>Below are SQL statements to find the text you&#8217;re looking for.</p>
<p>Using USER_SOURCE</p>
<blockquote><p>SELECT type, name, line<br />
FROM USER_SOURCE<br />
WHERE UPPER(text) LIKE UPPER(&#8216;%&amp;SearchText%&#8217;);</p></blockquote>
<p>Using DBA_SOURCE, or ALL_SOURCE</p>
<blockquote><p>SELECT type, name, line<br />
FROM ALL_SOURCE<br />
WHERE OWNER = &#8216;&amp;SCHEMA&#8217;<br />
AND UPPER(text) LIKE UPPER(&#8216;%&amp;SearchText%&#8217;);</p></blockquote>
<p>When you run a query above in SQL*Plus  you will be prompted for the  search text. Then, enter what you&#8217;re  looking for and you&#8217;re on your way.  These queries will return the following database types that contain the string your looking for :</p>
<ul>
<li>Packages</li>
<li>Procedures</li>
<li>Functions</li>
<li>Triggers</li>
<li>Types</li>
</ul>
<h2>Database Search</h2>
<p>To search for a given string in an entire Oracle database schema check out this awesome procedure by  <a title="David Yahalom" href="http://www.authoritybase.com/" target="_blank">David Yahalom</a> :  <a title="Search forf a given string in a shcema" href="http://it.toolbox.com/blogs/david/search-for-a-given-string-in-all-fields-of-an-entire-schema-24074" target="_blank">search_db</a></p>
<p>If you have scripts or other methods to search an Oracle database, please add them in a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pure-performance.com/2009/01/searching-oracle-databaseplsql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Welcome to Pure Performance</title>
		<link>http://www.pure-performance.com/2007/11/welcome/</link>
		<comments>http://www.pure-performance.com/2007/11/welcome/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 13:01:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PeopleSoft]]></category>
		<category><![CDATA[pure performance]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Wecome]]></category>

		<guid isPermaLink="false">http://pure-performance.com/2007/11/welcome/</guid>
		<description><![CDATA[Welcome to the updated site of Pure Performance Inc.  This site will be used to update our clients and clients to be  with our current activities.  We will also be providing tips and tricks for PeopleSoft, Oracle, Web, &#38; UNIX developers. Enjoy -Mark]]></description>
			<content:encoded><![CDATA[<p>Welcome to the updated site of Pure Performance Inc.  This site will be used to update our clients and clients to be  with our current activities.  We will also be providing tips and tricks for PeopleSoft, Oracle, Web, &amp; UNIX developers.</p>
<p>Enjoy -Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pure-performance.com/2007/11/welcome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
