<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-1068231502585385072</atom:id><lastBuildDate>Mon, 15 Mar 2010 15:13:08 +0000</lastBuildDate><title>Jon's Code blog</title><description></description><link>http://www.jhbproductions.com/blog/</link><managingEditor>noreply@blogger.com (Jon B.)</managingEditor><generator>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-6044141867612777926</guid><pubDate>Tue, 07 Apr 2009 21:25:00 +0000</pubDate><atom:updated>2009-05-20T14:47:56.081-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>alerts</category><category domain='http://www.blogger.com/atom/ns#'>tablespace</category><category domain='http://www.blogger.com/atom/ns#'>autoextend</category><category domain='http://www.blogger.com/atom/ns#'>oracle</category><title>Tablespace usage report (w/ autoextend)</title><description>If you use auto extending tablespaces in your Oracle environment and use Grid Control to monitor them, you will know that it does not take the auto extension into account. The following script will give you a breakout of your TS usage including the auto extension. I found the original script on Metalink and modified it slightly due to a flaw in the logic that would not include a TS if it was not in DBA_FREE_SPACE. This occurs when a TS has no free space left in it's current extent but has not moved into the next one yet.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;select&lt;br /&gt;a.tablespace_name,&lt;br /&gt;SUM(a.bytes)/1024/1024 "CurMb",&lt;br /&gt;SUM(decode(b.maxextend, null, A.BYTES/1024/1024, b.maxextend*8192/1024/1024)) "MaxMb",&lt;br /&gt;(SUM(a.bytes)/1024/1024 - round(c."Free"/1024/1024)) "TotalUsed",&lt;br /&gt;(SUM(decode(b.maxextend, null, A.BYTES/1024/1024, b.maxextend*8192/1024/1024)) - (SUM(a.bytes)/1024/1024 - round(c."Free"/1024/1024))) "TotalFree",&lt;br /&gt;round(100*(SUM(a.bytes)/1024/1024 - round(c."Free"/1024/1024))/(SUM(decode(b.maxextend, null, A.BYTES/1024/1024, b.maxextend*8192/1024/1024)))) "UPercent"&lt;br /&gt;from&lt;br /&gt;dba_data_files a,&lt;br /&gt;sys.filext$ b,&lt;br /&gt;(SELECT d.tablespace_name , sum(nvl(c.bytes,0)) "Free" FROM dba_tablespaces d,DBA_FREE_SPACE c where d.tablespace_name = c.tablespace_name(+) group by d.tablespace_name) c&lt;br /&gt;where a.file_id = b.file#(+)&lt;br /&gt;and a.tablespace_name = c.tablespace_name&lt;br /&gt;GROUP by a.tablespace_name, c."Free"/1024&lt;br /&gt;order by round(100*(SUM(a.bytes)/1024/1024 - round(c."Free"/1024/1024))/(SUM(decode(b.maxextend, null, A.BYTES/1024/1024, b.maxextend*8192/1024/1024)))) desc&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/1068231502585385072-6044141867612777926?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2009/04/tablespace-usage-report-w-autoextend.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-3220063702958218451</guid><pubDate>Mon, 15 Sep 2008 19:10:00 +0000</pubDate><atom:updated>2008-09-15T12:10:40.303-07:00</atom:updated><title>Get chained rows percentage</title><description>select owner,table_name,to_char((chain_cnt/num_rows)*100,'99.99') pct_chained&lt;br /&gt;from all_tables&lt;br /&gt;where num_rows &gt; 0&lt;br /&gt;and owner not in ('SYS','SYSTEM','OUTLN')&lt;br /&gt;order by to_char((chain_cnt/num_rows)*100,'99.99') desc&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-3220063702958218451?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2008/09/get-chained-rows-percentage.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-2964971195764265252</guid><pubDate>Tue, 12 Aug 2008 18:41:00 +0000</pubDate><atom:updated>2008-08-12T11:42:14.456-07:00</atom:updated><title>Select random row examples</title><description>http://www.petefreitag.com/item/466.cfm&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-2964971195764265252?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2008/08/select-random-row-examples.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-7643325450342631688</guid><pubDate>Tue, 27 Nov 2007 18:02:00 +0000</pubDate><atom:updated>2007-11-27T10:04:47.694-08:00</atom:updated><title>RMAN commands</title><description>List current archive logs:&lt;br /&gt;&lt;br /&gt;list archivelog all;&lt;br /&gt;&lt;br /&gt;Delete range by sequence #:&lt;br /&gt;&lt;br /&gt;delete archivelog sequence between N and N;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-7643325450342631688?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/11/rman-commands.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-3108118185563205850</guid><pubDate>Wed, 24 Oct 2007 18:17:00 +0000</pubDate><atom:updated>2007-10-24T11:20:23.016-07:00</atom:updated><title>Constraint Naming Conventions</title><description>Doesn't really matter how you feel about this as long as you are consistent.  I picked this up from comments on Dizwell's site and I basically like it.  The only thing I change is the use of table names except in the case of foreign keys.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt; Each table has a full name (employee) and a short name (emp) of three or four characters.&lt;/li&gt;&lt;li&gt;Each PK is named PM_short_name, so PK_EMP.&lt;/li&gt;&lt;li&gt;Each FK is named FK_parent_short_name_child_short_name and if more than one required, an additional sequence number is added as a suffix. So, FK_EMP_DEPT.&lt;/li&gt;&lt;li&gt;Check constraints are CHK_short_name_column_name - if at all possible. Alternatively, CHK_short_name_reason if it fits. Example, CHK_EMP_NAME or CHK_EMP_NAME_PRESENT.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Unique constraints are UQ_short_name_column where possible or UQ_SHORT_NAME_reason. For example, UQ_EMP_EMAIL.&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-3108118185563205850?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/10/constraint-naming-conventions.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-5626737930436837345</guid><pubDate>Tue, 16 Oct 2007 20:06:00 +0000</pubDate><atom:updated>2007-10-16T13:09:56.904-07:00</atom:updated><title>Power Architect is the best ERD drawing tool I've found</title><description>I spent 3 days trying everything out there and Power Architect came out the winner:&lt;br /&gt;&lt;br /&gt;http://www.sqlpower.ca/page/architect&lt;br /&gt;&lt;br /&gt;Free, simple, saves ERD as PDF, reverse engineers, Java based so it will run on anything.  A little buggy here and there but overall a great tool.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-5626737930436837345?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/10/power-architect-is-best-erd-drawing.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-8749497380163401517</guid><pubDate>Tue, 24 Jul 2007 21:57:00 +0000</pubDate><atom:updated>2007-07-24T15:03:57.073-07:00</atom:updated><title>Replace CRLF with CHR(13) to preserve new lines in Oracle</title><description>This example uses Perl to look for a CRLF and replace it with the the proper ASCII, it also concatenates it for Oracle:&lt;br /&gt;&lt;br /&gt;$text =~ s/(?:\r\n|[\r\n])/' || chr(13) || '/g;&lt;br /&gt;&lt;br /&gt;So, if you wanted to insert the following and preserve line breaks...&lt;br /&gt;&lt;br /&gt;Line 1&lt;br /&gt;Line 2&lt;br /&gt;&lt;br /&gt;...you can generate the following SQL:&lt;br /&gt;&lt;br /&gt;insert into table values ('Line 1' || chr(13) || 'Line 2');&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-8749497380163401517?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/07/replace-crlf-with-chr13-to-preserve-new.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-5464406453070053529</guid><pubDate>Thu, 05 Jul 2007 16:39:00 +0000</pubDate><atom:updated>2007-07-05T09:42:53.488-07:00</atom:updated><title>Finding Nth row in sql</title><description>substitute N for the row you want&lt;br /&gt;&lt;br /&gt;select * from YOUR_TABLE t1&lt;br /&gt;where (N-1) = (select count(distinct(t2.YOUR_COLUMN))&lt;br /&gt;              from YOUR_TABLE t2&lt;br /&gt;              and t2.YOUR_COLUMN &gt; t1.YOUR_COLUMN)&lt;br /&gt;&lt;br /&gt;This method is explained in detail here:&lt;br /&gt;&lt;br /&gt;http://www.sqlteam.com/article/find-nth-maximum-value-in-sql-server&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-5464406453070053529?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/07/finding-nth-row-in-sql.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-6701499412001306604</guid><pubDate>Tue, 24 Apr 2007 23:48:00 +0000</pubDate><atom:updated>2007-04-24T17:00:49.061-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>linux</category><category domain='http://www.blogger.com/atom/ns#'>batch</category><category domain='http://www.blogger.com/atom/ns#'>command line</category><category domain='http://www.blogger.com/atom/ns#'>rename</category><category domain='http://www.blogger.com/atom/ns#'>unix</category><title>use basename for batch rename</title><description>NOTE: Be careful with this.  Don't mess with your original files.   Files cannot contain spaces.&lt;br /&gt;&lt;br /&gt;Generic example:&lt;br /&gt;&lt;br /&gt;$ for f in *whatever; do mv $f `basename $f string_to_replace`string; done&lt;br /&gt;&lt;br /&gt;Real example (Rename a bunch of file named blah.M0703.xls to blah.xls):&lt;br /&gt;&lt;br /&gt;$ for f in *xls; do mv $f `basename $f M0703.xls`xls;done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-6701499412001306604?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/04/use-basename-for-batch-rename.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-3521755192336223435</guid><pubDate>Tue, 03 Apr 2007 22:11:00 +0000</pubDate><atom:updated>2007-04-03T15:12:29.357-07:00</atom:updated><title>Oracle delete duplicates</title><description>&lt;pre&gt;&lt;code&gt;DELETE FROM our_table&lt;br /&gt;WHERE rowid not in&lt;br /&gt;(SELECT MIN(rowid)&lt;br /&gt;FROM our_table&lt;br /&gt;GROUP BY column1, column2, column3...) ;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-3521755192336223435?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/04/oracle-delete-duplicates.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-1100317092278385543</guid><pubDate>Fri, 30 Mar 2007 16:44:00 +0000</pubDate><atom:updated>2007-03-30T10:27:53.535-07:00</atom:updated><title>Alternating row color by groups</title><description>As a DBA, I spend a lot of time looking at lists of rows and grouping them in various ways.  Visually it helps to alternate the color like so:&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;table style="width: 182px; height: 364px;" border="2" cellpadding="0" cellspacing="0"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;tr bgcolor="lightblue"&gt;&lt;td&gt;group 1&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr bgcolor="lightblue"&gt;&lt;td&gt;group 1&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr bgcolor="lightblue"&gt;&lt;td&gt;group 1&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr bgcolor=""&gt;&lt;td&gt;group 2&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr bgcolor=""&gt;&lt;td&gt;group 2&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr bgcolor="lightblue"&gt;&lt;td&gt;group 3&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr bgcolor="lightblue"&gt;&lt;td&gt;group 3&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr bgcolor="lightblue"&gt;&lt;td&gt;group 3&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr bgcolor=""&gt;&lt;td&gt;group 4&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;I can never remember the logic to do this so hear it is (in PHP/Oracle) for future reference:&lt;br /&gt;&lt;/p&gt;while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS)){&lt;br /&gt;    if(!$temp || $temp_zname &lt;&gt; $row[MEMBER_TO_GROUP_BY]){&lt;br /&gt;        $temp = $row[MEMBER_TO_GROUP_BY];&lt;br /&gt;        $bgcolor = ($bgcolor == 'lightblue') ? '' : 'lightblue';&lt;br /&gt;    }&lt;br /&gt;    print "&amp;lt;tr bgcolor=$bgcolor&amp;gt;";&lt;br /&gt;    print "&amp;lt;td&amp;gt;". $row[MEMBER_TO_GROUP_BY] . "&amp;lt;/td&amp;gt;";&lt;br /&gt;    print "&amp;lt;/tr&amp;gt;";&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-1100317092278385543?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/03/alternating-row-color-by-groups.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-470176249381785566</guid><pubDate>Wed, 21 Mar 2007 16:57:00 +0000</pubDate><atom:updated>2007-03-21T09:59:30.368-07:00</atom:updated><title>Oracle Date Functions</title><description>Puget Sound Oracle Users Group = Best Oracle Documentation (IMHO)&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.psoug.org/reference/date_func.html"&gt;http://www.psoug.org/reference/date_func.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-470176249381785566?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/03/oracle-date-functions.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1068231502585385072.post-4757590805928787050</guid><pubDate>Thu, 04 Jan 2007 22:35:00 +0000</pubDate><atom:updated>2007-01-15T14:21:23.548-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>trigger</category><category domain='http://www.blogger.com/atom/ns#'>oracle</category><title>Trigger to mimic MySQL "last modified" datatype in Oracle</title><description>ALTER TABLE YOUR_TABLE ADD (LAST_MODIFIED DATE);&lt;br /&gt;&lt;br /&gt;CREATE OR REPLACE&lt;br /&gt;TRIGGER YOUR_TABLE_BEFORE_INS_UPD BEFORE INSERT OR UPDATE&lt;br /&gt;ON YOUR_TABLE&lt;br /&gt;FOR EACH ROW&lt;br /&gt;DECLARE CURRENT_TIME DATE;&lt;br /&gt;BEGIN&lt;br /&gt;CURRENT_TIME := SYSDATE;&lt;br /&gt;:new.last_modified := CURRENT_TIME;&lt;br /&gt;END;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1068231502585385072-4757590805928787050?l=www.jhbproductions.com%2Fblog%2Findex.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.jhbproductions.com/blog/2007/01/trigger-for-last-modified-column-in.html</link><author>noreply@blogger.com (Jon B.)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>13</thr:total></item></channel></rss>
