<?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-22250741</id><updated>2012-01-23T11:39:39.942-08:00</updated><category term='linux vm virtualbox'/><title type='text'>Oracle SQL tips and tricks + Unix/Linux Work Log</title><subtitle type='html'>See how much a single Oracle SQL statement can do...
Plus some Unix/Linux Work Log</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>42</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-22250741.post-3935697396207897651</id><published>2012-01-23T11:17:00.000-08:00</published><updated>2012-01-23T11:39:40.128-08:00</updated><title type='text'>simplest cgo program</title><content type='html'>Have been struggling to make a simple cgo sample to get familiar on how to link c code and go library. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Finally made it working.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;cgo_test.go&lt;/div&gt;&lt;div&gt;-------------------------------&lt;/div&gt;&lt;div&gt;&lt;div&gt;package cgo_test&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;/*&lt;/div&gt;&lt;div&gt;#include &lt;stdio.h&gt;&lt;/stdio.h&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;void out() {&lt;/div&gt;&lt;div&gt;&lt;span style="background-color: rgb(240, 224, 192); font-family: verdana, arial, geneva, sans-serif; font-size: 13px; "&gt; &lt;/span&gt;  printf("Hello world from c\n");&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;*/&lt;/div&gt;&lt;div&gt;import "C"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;func Out() {&lt;/div&gt;&lt;div&gt;  C.out()&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;--------------------------------------------------------&lt;/div&gt;&lt;div&gt;main.go&lt;/div&gt;&lt;div&gt;-------------------------------------------------------- &lt;/div&gt;&lt;div&gt;&lt;div&gt;package main&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import "cgo_test"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;func main() {&lt;/div&gt;&lt;div&gt;  cgo_test.Out()&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;--------------------------------------------------------&lt;/div&gt;&lt;div&gt;Makefile&lt;/div&gt;&lt;div&gt;--------------------------------------------------------&lt;/div&gt;&lt;div&gt;&lt;div&gt;include ../go/src/Make.inc&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;TARG=cgo_test&lt;/div&gt;&lt;div&gt;CGOFILES=cgo_test.go&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;CLEANFILES+=main&lt;/div&gt;&lt;div&gt;include ../go/src/Make.pkg&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;main: install main.go&lt;/div&gt;&lt;div&gt;  $(GC) main.go&lt;/div&gt;&lt;div&gt;  $(LD) -o $@ main.$O&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;The most annoy error message I got is something like:&lt;/div&gt;&lt;div&gt;gomake main&lt;/div&gt;&lt;div&gt;&lt;div&gt;main.go:6: cannot refer to unexported name cgo_test.out&lt;/div&gt;&lt;div&gt;main.go:6: undefined: cgo_test.out&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It seems that GO only export Initcap names by default.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-3935697396207897651?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/3935697396207897651/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=3935697396207897651' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/3935697396207897651'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/3935697396207897651'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2012/01/simplest-cgo-program.html' title='simplest cgo program'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-1606088277140293336</id><published>2012-01-21T21:27:00.000-08:00</published><updated>2012-01-21T21:47:25.644-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux vm virtualbox'/><title type='text'>VirtualBox Scientific Linux Issues and Resolution</title><content type='html'>* Change the default screen resolution 1024x768&lt;div&gt;   Resolution: &lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;Install VboxAddtions&lt;/li&gt;&lt;li&gt;Define the new resolution with xrandra &amp;amp; cvt&lt;/li&gt;&lt;li style="text-align: left;"&gt;&lt;span style="background-color: rgb(255, 255, 255); text-align: justify; "&gt;Add the new mode into&lt;/span&gt;&lt;span style="background-color: rgb(255, 255, 255); font-family: Tahoma, Arial, Helvetica; font-size: 12px; line-height: 20px; text-align: justify; "&gt; /etc/gdm/Init/Default to make it permanent&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;xrandr --newmode "1440x900"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;xrandr --addmode VBOX0 1440x900&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;xrandr --output VBOX0 --mode 1440x900&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;    Details can be found at: &lt;a href="http://www.ubuntugeek.com/how-change-display-resolution-settings-using-xrandr.html"&gt;http://www.ubuntugeek.com/how-change-display-resolution-settings-using-xrandr.html&lt;/a&gt;&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;* The New IME ibus&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;     For RH5.*, scim is the default IME. Now Ibus takes its position. The problem is that the Ibus is not setup correctly after installation. I've go "No input windows" for all the applications:&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;     Resolution:&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-size: 12px; line-height: 20px;"&gt;Enable the ibus daemon from "System" -&amp;gt; "Preference" -&amp;gt; "Startup Applications", add an entry with command "/usr/bin/ibus-daemon -d"&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: 12px; line-height: 20px;"&gt;Add 3 lines into your bash profile (/etc/profile or .bashrc or .bash_profile)&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-size: 12px; line-height: 20px;"&gt;&lt;b&gt;             export GTK_IM_MODULE=ibus&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-size: 12px; line-height: 20px;"&gt;&lt;b&gt;             export XMODIFIERS=@im=ibus&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-size: 12px; line-height: 20px;"&gt;&lt;b&gt;             export QT_IM_MODULE=ibus&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;font-size: 12px; line-height: 20px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="font-size: 12px; line-height: 20px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div&gt;   &lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-1606088277140293336?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/1606088277140293336/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=1606088277140293336' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/1606088277140293336'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/1606088277140293336'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2012/01/virtualbox-scientific-linux-issues-and.html' title='VirtualBox Scientific Linux Issues and Resolution'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-8110804279275255704</id><published>2010-12-10T11:32:00.001-08:00</published><updated>2010-12-10T11:41:15.190-08:00</updated><title type='text'>Chacterset issue with SQL loader and external table</title><content type='html'>Just had an issue with different contents for tables loaded with sqlldr and external table for a same input data file.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The issue is mainly caused by the different default behavior on the characterset of these 2 methods.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For external table, if character set is not specified, oracle assumes the data file has the same character set with the database.  The DB characterset can be found with the following query:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: monospace; font-size: 12px; font-weight: bold; white-space: pre; "&gt;SQL&gt; select value from nls_database_parameters where parameter='NLS_CHARACTERSET';&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: monospace; font-size: 12px; font-weight: bold; white-space: pre; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" &gt;&lt;span class="Apple-style-span" style="font-size: 12px; white-space: pre;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Georgia, serif; font-weight: normal; white-space: normal; font-size: 16px; "&gt;For sqlldr, if characterset is not specified, it will try to use the value found in your client side NLS_LANG. If NLS_LANG is not set, it uses the default value, which is &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 13px; font-weight: bold; "&gt;AMERICAN_AMERICA.US7ASCII .&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 13px; font-weight: bold; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 13px; font-weight: bold; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" &gt;&lt;span class="Apple-style-span" style="font-size: 12px; white-space: pre;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Georgia, serif; font-weight: normal; white-space: normal; font-size: 16px; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 13px; "&gt;&lt;pre style="color: black; font-size: 12px; "&gt;&lt;span style="font-weight: bold; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="color: black; font-size: 12px; "&gt;&lt;span style="font-weight: bold; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-8110804279275255704?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/8110804279275255704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=8110804279275255704' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/8110804279275255704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/8110804279275255704'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2010/12/chacterset-issue-with-sql-loader-and.html' title='Chacterset issue with SQL loader and external table'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-278026506611530215</id><published>2010-10-08T17:01:00.000-07:00</published><updated>2010-10-08T17:15:51.467-07:00</updated><title type='text'>Step by step Installation guide: Linkedin Azkaban as a webapp on redhat linux tomcat</title><content type='html'>Before you start, make sure you have tomcat installed and running with "service status tomcat5".&lt;br /&gt;&lt;ul&gt;&lt;li&gt;download the latest azkaban tarball to /opt at http://github.com/downloads/azkaban/azkaban/azkaban-0.04.tar.gz&lt;/li&gt;&lt;li&gt;tar -xvf azkaban-0.04.tar.gz&lt;/li&gt;&lt;li&gt;copy azkaban-0.04/dist/war/azkaban.war /var/lib/tomcat5/webapps&lt;/li&gt;&lt;li&gt;stop tomcat service: service tomcat5 stop&lt;/li&gt;&lt;li&gt;append "AZKABAN_HOME="/opt/azkaban-0.04" into /etc/sysconfig/tomcat5&lt;/li&gt;&lt;li&gt;start tomcat service: service tomcat&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;wait for a couple of minus, you should get azkaban running at http://your_host_name:port/azkaban/&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-278026506611530215?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/278026506611530215/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=278026506611530215' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/278026506611530215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/278026506611530215'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2010/10/step-by-step-installation-guide.html' title='Step by step Installation guide: Linkedin Azkaban as a webapp on redhat linux tomcat'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-916230943350669767</id><published>2010-09-14T21:34:00.000-07:00</published><updated>2010-09-22T11:13:21.505-07:00</updated><title type='text'>Query to get tablespace contiguous spaces</title><content type='html'>Ever getting ORA-01659: unable to allocate MINEXTENTS beyond 8 in tablespace XYZ?&lt;br /&gt;&lt;br /&gt;I got this last weekend when creating a table with several GB level partitions.&lt;br /&gt;&lt;br /&gt;The error indicates that it can not find contiguous spaces to create initial extents * minextents.&lt;br /&gt;&lt;br /&gt;How do we know how many contiguous spaces we have on the tablespace, I tried to search the web but only got lengthy complex PL/SQL scripts. It ends with that I have to write my own. I post it here hoping someday it may help somebody.&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;tablespace_name,&lt;br /&gt;file_id,&lt;br /&gt;round(sum(bytes)/1024/1024/1024, 3) contiguous_free_space_gb,&lt;br /&gt;sum(blocks) no_of_blocks,&lt;br /&gt;min(block_id) as starting_block,&lt;br /&gt;round((sum(sum(bytes)) over ())/1024/1024/1024, 3) total_ts_free_space_gb&lt;br /&gt;FROM&lt;br /&gt;(&lt;br /&gt;SELECT&lt;br /&gt;tablespace_name,&lt;br /&gt;file_id,&lt;br /&gt;block_id,&lt;br /&gt;bytes,&lt;br /&gt;blocks,&lt;br /&gt;nvl(block_id - min(block_id) over (partition by file_id) - sum(blocks) over (partition by file_id order by block_id rows between unbounded preceding and 1 preceding), 0) gap_blocks&lt;br /&gt;FROM dba_free_space&lt;br /&gt;WHERE tablespace_name = '&amp;amp;ts_name'&lt;br /&gt;)&lt;br /&gt;GROUP BY gap_blocks, tablespace_name, file_id&lt;br /&gt;ORDER BY sum(bytes) desc&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-916230943350669767?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/916230943350669767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=916230943350669767' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/916230943350669767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/916230943350669767'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2010/09/query-to-get-tablespace-contiguous.html' title='Query to get tablespace contiguous spaces'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-1887633037786640402</id><published>2010-04-01T23:18:00.000-07:00</published><updated>2010-09-14T21:52:00.224-07:00</updated><title type='text'>やられた</title><content type='html'>It was 5:00PM and I was asked to write a function which needs to parse a comma delimited string. I was lazy and trying to avoid the lengthy substr/instr loop. I remember I read somewhere that there is builtin function exactly does the same  thing.&lt;br /&gt;After a search, I found out the function dbms_utility.comma_to_table and that's when the nightmare started.&lt;br /&gt;&lt;br /&gt;After I finished the function and tested with 'abc,efg', it works well.&lt;br /&gt;When I put it into real use&lt;br /&gt;This is what I got:&lt;br /&gt;ORA-00931: missing identifier&lt;br /&gt;ORA-06512: at "SYS.DBMS_UTILITY", line 125&lt;br /&gt;ORA-06512: at "SYS.DBMS_UTILITY", line 160&lt;br /&gt;ORA-06512: at "SYS.DBMS_UTILITY", line 202&lt;br /&gt;ORA-06512: at line 7&lt;br /&gt;00931. 00000 -  "missing identifier"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;http://www.dbforums.com/oracle/887432-dbms_utility-comma_to_table-giving-problem.html&lt;br /&gt;"Unfortunately dbms_utility.comma_to_table is NOT a general purpose utility as its name would suggest. It only works with comma-separated names that are valid database object names, i.e. up to 30 chars beginning with a letter"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-1887633037786640402?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/1887633037786640402/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=1887633037786640402' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/1887633037786640402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/1887633037786640402'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2010/04/blog-post.html' title='やられた'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-6878649213631597798</id><published>2008-12-23T19:21:00.000-08:00</published><updated>2008-12-23T19:26:51.693-08:00</updated><title type='text'>Postgresql 8.3 on OpenSolaris 2008-11</title><content type='html'>Here are the steps to enable postgresql 8.3 on OpenSolaris 2008-11.&lt;br /&gt;&lt;br /&gt;* Install all the 8.3 relate package with Package Manager.&lt;br /&gt;* Enable the service:&lt;br /&gt;    svcadm enable postgresql_83:default_32bit&lt;br /&gt;* Connect to database:&lt;br /&gt;    psql -U postgres postgres&lt;br /&gt;&lt;br /&gt;List Service Status&lt;br /&gt;    svcs -a | grep postgres&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-6878649213631597798?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/6878649213631597798/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=6878649213631597798' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/6878649213631597798'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/6878649213631597798'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2008/12/postgresql-83-on-opensolaris-2008-11.html' title='Postgresql 8.3 on OpenSolaris 2008-11'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-4300036053236316268</id><published>2008-11-08T20:34:00.000-08:00</published><updated>2008-11-09T13:38:54.562-08:00</updated><title type='text'>ABS - Advanced Bash Scripting</title><content type='html'>If you are serious about shell programming, you are gonna read this:&lt;br /&gt;&lt;br /&gt;http://personal.riverusers.com/~thegrendel/abs-guide.pdf&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-4300036053236316268?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/4300036053236316268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=4300036053236316268' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/4300036053236316268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/4300036053236316268'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2008/11/abs-advanced-bash-programming.html' title='ABS - Advanced Bash Scripting'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-3886182323297507673</id><published>2008-10-23T16:55:00.000-07:00</published><updated>2008-10-23T17:04:02.071-07:00</updated><title type='text'>Bash ANSI-C quoting</title><content type='html'>The syntax of ANSI-C quoting is something like&lt;br /&gt;$'\0x009' or $'\t'.&lt;br /&gt;&lt;br /&gt;This is useful when you want to input a tab on the command line as an input parameter (tab key is mapped to auto-completion in bash).&lt;br /&gt;&lt;br /&gt;for example:&lt;br /&gt;psql -A -F $'\t' ...&lt;br /&gt;will set the field separator to tab.&lt;br /&gt;&lt;br /&gt;This is documented in http://www.faqs.org/docs/bashman/bashref_12.html as:&lt;br /&gt;"Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For tab, you can also input a CTRL-I (type CTRL-V-I).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-3886182323297507673?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/3886182323297507673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=3886182323297507673' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/3886182323297507673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/3886182323297507673'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2008/10/bash-ansi-c-encoding.html' title='Bash ANSI-C quoting'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-5314542508727555375</id><published>2008-09-16T09:49:00.000-07:00</published><updated>2008-09-16T09:52:36.859-07:00</updated><title type='text'>IFILE for oracle parameter files</title><content type='html'>Use IFILE to embed another parameter file within the current parameter file. (Maximum level 3)&lt;br /&gt;&lt;br /&gt;It works for any oracle parameter files including tnsnames.ora.&lt;br /&gt;&lt;br /&gt;http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams081.htm#REFRN10070&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Credit goes to my friend Matthew!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-5314542508727555375?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/5314542508727555375/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=5314542508727555375' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/5314542508727555375'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/5314542508727555375'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2008/09/ifile-for-oracle-parameter-files.html' title='IFILE for oracle parameter files'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-2936989865039049604</id><published>2008-06-26T11:04:00.000-07:00</published><updated>2008-06-26T11:31:58.427-07:00</updated><title type='text'>Clean up the old oracle installation</title><content type='html'>A short memo on how to clean up your previous installation on Windows:&lt;br /&gt;&lt;br /&gt;0). Stop all the Oracle Related Service if you have the database installed&lt;br /&gt;    Control Panel -&gt; Adminstrative Tools -&gt; Services&lt;br /&gt;&lt;br /&gt;1). Remove all the Oracle related ODBC Data Sources.&lt;br /&gt;  Control Panel -&gt; Adminstrative Tools -&gt;  Data Sources (ODBC)&lt;br /&gt;  Remove all Oracle related User DSN/System DSN&lt;br /&gt;  &lt;br /&gt;  ODBC driver hooks up with the oracle dlls which blocks you to remove Oracle components&lt;br /&gt;&lt;br /&gt;2). Reboot&lt;br /&gt;&lt;br /&gt;3). Run the oracle installer to remove whatever can be removed.&lt;br /&gt;&lt;br /&gt;4). Remove the Oracle registration key with regedit.exe&lt;br /&gt;   HK_LOCAL_MACHINE/Software/Oracle&lt;br /&gt;   HK_LOCAL_MACHINE/System/Services (if you have the database installed)&lt;br /&gt;&lt;br /&gt;5). Reboot&lt;br /&gt;&lt;br /&gt;6). Remove the Oracle Folders&lt;br /&gt;  Typically c:\oracle or c:\orant &amp; C:\Program Files\Oracle&lt;br /&gt;&lt;br /&gt;Now you are clean and ready for a reinstallation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-2936989865039049604?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/2936989865039049604/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=2936989865039049604' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/2936989865039049604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/2936989865039049604'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2008/06/clean-up-old-oracle-installation.html' title='Clean up the old oracle installation'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-3735097009161398979</id><published>2007-12-18T17:23:00.000-08:00</published><updated>2007-12-18T17:26:25.029-08:00</updated><title type='text'>Direct Oracle Connection without Tnsnames.ora</title><content type='html'>sqlplus username/xxxxx@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=machine_name)(Port=1521))(CONNECT_DATA=(SID=service_name))) &lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;sqlplus username/xxxxx@machine_name:port/sid&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-3735097009161398979?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/3735097009161398979/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=3735097009161398979' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/3735097009161398979'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/3735097009161398979'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2007/12/direct-oracle-connection-without.html' title='Direct Oracle Connection without Tnsnames.ora'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-6194997563805129759</id><published>2007-10-03T16:14:00.000-07:00</published><updated>2007-10-03T16:16:28.870-07:00</updated><title type='text'>Convert a stats input date to Edward date_sid</title><content type='html'>Old way of doing it:&lt;br /&gt;select to_char(to_date('09/01/2007', 'MM/DD/YYYY'), 'YYYYMMDD') from dual;&lt;br /&gt;&lt;br /&gt;New way with regexp&lt;br /&gt;select regexp_replace('09/01/2007', '(\d{2})/(\d{2})/(\d{4})', '\3\2\1') from dual&lt;br /&gt;&lt;br /&gt;reduced function call to 1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-6194997563805129759?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/6194997563805129759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=6194997563805129759' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/6194997563805129759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/6194997563805129759'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2007/10/convert-stats-input-date-to-edward.html' title='Convert a stats input date to Edward date_sid'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-1565572793549573941</id><published>2007-08-20T17:18:00.000-07:00</published><updated>2007-08-20T17:39:41.998-07:00</updated><title type='text'>Oracle 11g password and Toad (connection issue)</title><content type='html'>One of the new features of 11g is case-sensitive password.&lt;br /&gt;&lt;br /&gt;It causes problem for Toad because Toad makes the password captial silently.&lt;br /&gt;&lt;br /&gt;If you are using lower case password, you will get&lt;br /&gt;ORA-01017: invalid username/password; logon denied.&lt;br /&gt;&lt;br /&gt;How to disable this new featuer:&lt;br /&gt;alter system set sec_case_sensitive_logon=FALSE;&lt;br /&gt;&lt;br /&gt;A new column PASSWORD_VERSIONS has been added in dba_users may be related to this.&lt;br /&gt;Not quite sure on this. &lt;br /&gt;The values (10G 11G) remine same before/after changing the system parameter sec_case_sensitive_logon.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-1565572793549573941?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/1565572793549573941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=1565572793549573941' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/1565572793549573941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/1565572793549573941'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2007/08/oracle-11g-password.html' title='Oracle 11g password and Toad (connection issue)'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-6015484337398679691</id><published>2007-05-25T15:56:00.000-07:00</published><updated>2007-05-25T15:58:20.689-07:00</updated><title type='text'>Unix Shell Integer Comparison</title><content type='html'>In Unix shell,&lt;br /&gt;&lt;br /&gt;Use -ne -eq -lt -gt to compare numbers.&lt;br /&gt;&lt;br /&gt;== and != are used for string comparison.&lt;br /&gt;&lt;br /&gt;Perl does the things on the opposite.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-6015484337398679691?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/6015484337398679691/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=6015484337398679691' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/6015484337398679691'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/6015484337398679691'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2007/05/unix-shell-integer-comparison.html' title='Unix Shell Integer Comparison'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-5286563396381603191</id><published>2007-05-22T16:43:00.000-07:00</published><updated>2007-05-22T16:44:59.157-07:00</updated><title type='text'>Initcap</title><content type='html'>An interesting function:&lt;br /&gt;&lt;br /&gt;SQL&gt; select initcap('abc XYZ') from dual;&lt;br /&gt;&lt;br /&gt;INITCAP('ABCXY&lt;br /&gt;--------------&lt;br /&gt;Abc Xyz&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-5286563396381603191?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/5286563396381603191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=5286563396381603191' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/5286563396381603191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/5286563396381603191'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2007/05/initcap.html' title='Initcap'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-2635235316884882907</id><published>2007-01-27T04:45:00.000-08:00</published><updated>2007-01-27T04:46:24.884-08:00</updated><title type='text'>Scalar query and parallel query</title><content type='html'>If you have a scalar query in the select list, the whole query will not work in parallel mode even if you give a parallel hint&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-2635235316884882907?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/2635235316884882907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=2635235316884882907' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/2635235316884882907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/2635235316884882907'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2007/01/scalar-query-and-parallel-query.html' title='Scalar query and parallel query'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-3815477024097146841</id><published>2007-01-18T07:14:00.000-08:00</published><updated>2007-01-18T07:24:01.358-08:00</updated><title type='text'>(Unix/Linux Shell) How many lines in a file?</title><content type='html'>Linux (FC6)&lt;br /&gt;&lt;br /&gt;wc -l tx.txt | cut -f 1 -d " "&lt;br /&gt;&lt;br /&gt;Solaris&lt;br /&gt;&lt;br /&gt;wc -l tx.txt | sed -e 's/^ *//' | cut -f 1 -d " "&lt;br /&gt;OR&lt;br /&gt;wc -l txt.txt | awk '{print $1}'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-3815477024097146841?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/3815477024097146841/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=3815477024097146841' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/3815477024097146841'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/3815477024097146841'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2007/01/unixlinux-shell-how-many-lines-in-file.html' title='(Unix/Linux Shell) How many lines in a file?'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-5783017750158363859</id><published>2006-12-28T01:00:00.000-08:00</published><updated>2006-12-28T01:02:27.301-08:00</updated><title type='text'>Substr in unix/linux shell script</title><content type='html'>Linux: expr substr 1 3&lt;br /&gt;Solaris: awk '{print substr($1,  1,3}' (the expr in solaris does not support substr)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-5783017750158363859?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/5783017750158363859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=5783017750158363859' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/5783017750158363859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/5783017750158363859'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/12/substr-in-unixlinux-shell-script.html' title='Substr in unix/linux shell script'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-7191642424735241522</id><published>2006-12-26T01:12:00.000-08:00</published><updated>2006-12-26T01:19:37.218-08:00</updated><title type='text'>Access windows file server from Linux</title><content type='html'>1. Use smbclient (a ftp-like client allows you put/get file)&lt;br /&gt;&lt;br /&gt;smbclient -U Windows_Domain\\user //windows_file_server_name/dir&lt;br /&gt;&lt;br /&gt;it prompts for your windows password&lt;br /&gt;&lt;br /&gt;2. Mount the file server&lt;br /&gt;&lt;br /&gt;mount -t cifs '//windows_file_server_name/dir' /mnt/mount_point -o username=Windows_Domain\\user,rw,iocharset=utf8&lt;br /&gt;&lt;br /&gt;After typing your windows password, you can access the files on the windows server&lt;br /&gt;cd /mnt/mount_point&lt;br /&gt;ls -l&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;The above are tested in FC6&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-7191642424735241522?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/7191642424735241522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=7191642424735241522' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/7191642424735241522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/7191642424735241522'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/12/access-windows-file-server-from-linux.html' title='Access windows file server from Linux'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-116588873418438940</id><published>2006-12-11T17:53:00.000-08:00</published><updated>2006-12-26T01:12:40.120-08:00</updated><title type='text'>Sort tab delimited Japanese Data (unix)</title><content type='html'>sort -t ******** # push a tab key here, it wouldn't accept \t&lt;br /&gt;&lt;br /&gt;in zsh, it will be a no-go because tab is assigned for auto-completion. You may need to create a shell file and put the command in.&lt;br /&gt;&lt;br /&gt;the file would like&lt;br /&gt;&lt;br /&gt;sort -t " " ......&lt;br /&gt;&lt;br /&gt;In order to sort Japanese Data, you have to set LANG=jp_JP.UTF-8 for Linux&lt;br /&gt;For Solaris LC_CTYPE=jp_JP.UTF-8 will do the thing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-116588873418438940?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/116588873418438940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=116588873418438940' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/116588873418438940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/116588873418438940'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/12/sort-delimited-japanese-data-unix.html' title='Sort tab delimited Japanese Data (unix)'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-116418790371647804</id><published>2006-11-22T01:30:00.000-08:00</published><updated>2006-11-22T01:31:43.726-08:00</updated><title type='text'>Decimal to hex and vice versa</title><content type='html'>select to_char(134829, 'XXXXX') from dual;&lt;br /&gt;select to_number('AFF0', 'XXXXXX') from dual;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-116418790371647804?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/116418790371647804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=116418790371647804' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/116418790371647804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/116418790371647804'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/11/decimal-to-hex-and-vice-versa.html' title='Decimal to hex and vice versa'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-115622671659997567</id><published>2006-08-21T23:03:00.000-07:00</published><updated>2006-08-21T23:05:16.610-07:00</updated><title type='text'>Merge continuous ranges</title><content type='html'>SQL&gt; select * from test;&lt;br /&gt;&lt;br /&gt;        ID          S          E&lt;br /&gt;---------- ---------- ----------&lt;br /&gt;         1          1          5&lt;br /&gt;         1          5          7&lt;br /&gt;         1          8         12&lt;br /&gt;         1         12         19&lt;br /&gt;&lt;br /&gt;SELECT   ID, MIN (x), MAX (x)&lt;br /&gt;    FROM (SELECT CEIL (ROWNUM / 2) rn, ID, x&lt;br /&gt;            FROM ((SELECT ID, s x&lt;br /&gt;                     FROM TEST&lt;br /&gt;                   MINUS&lt;br /&gt;                   SELECT ID, e x&lt;br /&gt;                     FROM TEST)&lt;br /&gt;                  UNION&lt;br /&gt;                  (SELECT ID, e x&lt;br /&gt;                     FROM TEST&lt;br /&gt;                   MINUS&lt;br /&gt;                   SELECT ID, s x&lt;br /&gt;                     FROM TEST)))&lt;br /&gt;GROUP BY ID, rn&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        ID     MIN(X)     MAX(X)&lt;br /&gt;---------- ---------- ----------&lt;br /&gt;         1          8         19&lt;br /&gt;         1          1          7&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-115622671659997567?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/115622671659997567/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=115622671659997567' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/115622671659997567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/115622671659997567'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/08/merge-continuous-ranges.html' title='Merge continuous ranges'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-115528396363914007</id><published>2006-08-11T01:04:00.000-07:00</published><updated>2006-08-11T01:12:43.640-07:00</updated><title type='text'>SSH port forwarding on Unix/Linux</title><content type='html'>ssh -L your_client_ip_or_name:port1:destination_ip_or_name:22 proxy_ip_or_name -l username&lt;br /&gt;&lt;br /&gt;your_client_id_or_name (The machine you want to start the connection to destination)&lt;br /&gt;port1:whatever port in the client machine&lt;br /&gt;destination_ip_or_name (the machine you want to connect to)&lt;br /&gt;proxy_ip_or_name (The machine used as proxy, it is connectable to your_client and destination)&lt;br /&gt;&lt;br /&gt;ssh -p port1 your_client_ip_or_name&lt;br /&gt;this will connect you to destination &lt;br /&gt;&lt;br /&gt;client -&gt; client port 1 -&gt; proxy -&gt; destination&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-115528396363914007?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/115528396363914007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=115528396363914007' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/115528396363914007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/115528396363914007'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/08/ssh-port-forwarding-on-unixlinux.html' title='SSH port forwarding on Unix/Linux'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-115528340080174755</id><published>2006-08-11T01:02:00.000-07:00</published><updated>2006-08-11T01:04:44.170-07:00</updated><title type='text'>Converting Unix time_t to Oracle Date</title><content type='html'>select to_date(19700101, 'YYYYMMDD') + unix_time_t/(24*60*60) from dual;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-115528340080174755?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/115528340080174755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=115528340080174755' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/115528340080174755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/115528340080174755'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/08/converting-unix-timet-to-oracle-date.html' title='Converting Unix time_t to Oracle Date'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-115254098157503804</id><published>2006-07-10T07:15:00.000-07:00</published><updated>2006-07-10T07:16:21.590-07:00</updated><title type='text'>dump &amp; zip the dmp file on the fly</title><content type='html'># create a named pipe&lt;br /&gt;        mknod exp.pipe p&lt;br /&gt;        # read the pipe - output to zip file in the background&lt;br /&gt;        gzip &lt; exp.pipe &gt; scott.exp.gz &amp;&lt;br /&gt;        # feed the pipe&lt;br /&gt;        exp userid=scott/tiger file=exp.pipe ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-115254098157503804?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/115254098157503804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=115254098157503804' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/115254098157503804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/115254098157503804'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/07/dump-zip-dmp-file-on-fly.html' title='dump &amp; zip the dmp file on the fly'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-114722737986335934</id><published>2006-05-09T19:13:00.000-07:00</published><updated>2006-05-09T19:16:19.873-07:00</updated><title type='text'>SQL Loader: Skip column</title><content type='html'>In the control file, you can specify a filler column so that it will be skipped.&lt;br /&gt;&lt;br /&gt;SQL&gt; desc dept&lt;br /&gt; Name                   &lt;br /&gt; -----------------&lt;br /&gt; DEPTNO                 &lt;br /&gt; DNAME                  &lt;br /&gt; LOC                    &lt;br /&gt;&lt;br /&gt;Control File&lt;br /&gt;&lt;br /&gt;LOAD DATA&lt;br /&gt;INFILE *&lt;br /&gt;INTO TABLE dept&lt;br /&gt;FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'&lt;br /&gt;(x filler integer, dname, loc)&lt;br /&gt;BEGINDATA&lt;br /&gt;12,RESEARCH,"SARATOGA"&lt;br /&gt;10,"ACCOUNTING",CLEVELAND&lt;br /&gt;&lt;br /&gt;It will allow you only load value for column dname and loc. The first column ID will be skipped.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-114722737986335934?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/114722737986335934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=114722737986335934' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114722737986335934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114722737986335934'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/05/sql-loader-skip-column.html' title='SQL Loader: Skip column'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-114655311733839842</id><published>2006-05-01T23:50:00.000-07:00</published><updated>2006-05-01T23:58:37.346-07:00</updated><title type='text'>One row goes to two groups</title><content type='html'>SQL&gt; select * from tst;&lt;br /&gt;&lt;br /&gt;        C1         C2         C3&lt;br /&gt;---------- ---------- ----------&lt;br /&gt;         1                   150&lt;br /&gt;         1          1         80&lt;br /&gt;         1          2         90&lt;br /&gt;         1          1        130&lt;br /&gt;         1          3        120&lt;br /&gt;&lt;br /&gt;Make sum on C2 based on group (c1, c2), the special requirement is&lt;br /&gt;within the group of (1, null), it should include 10% of the sum of&lt;br /&gt;other groups which c2 is not null. To achive this, one row will go&lt;br /&gt;to 2 groups. one for itself and one maps to (c1, null).&lt;br /&gt;&lt;br /&gt;The query will be&lt;br /&gt;&lt;br /&gt;select&lt;br /&gt;C1,&lt;br /&gt;(CASE WHEN TYPE = 1 THEN C2&lt;br /&gt;     WHEN TYPE = 2 THEN NULL&lt;br /&gt; END) C2,&lt;br /&gt;SUM(CASE WHEN TYPE = 1 THEN C3&lt;br /&gt;    WHEN TYPE = 2 AND C2 IS NOT NULL THEN C3*0.1&lt;br /&gt;    ELSE NULL&lt;br /&gt;    END) C3_SUM&lt;br /&gt;from&lt;br /&gt;(&lt;br /&gt;select c1, c2, sum(c3) c3&lt;br /&gt;from tst&lt;br /&gt;group by c1, c2&lt;br /&gt;), (select 1 type from dual union all select 2 type from dual&lt;br /&gt;)&lt;br /&gt;group by&lt;br /&gt;C1,&lt;br /&gt;(CASE WHEN TYPE = 1 THEN C2&lt;br /&gt;     WHEN TYPE = 2 THEN NULL&lt;br /&gt; END)&lt;br /&gt;&lt;br /&gt;and result is&lt;br /&gt;&lt;br /&gt;        C1         C2     C3_SUM&lt;br /&gt;---------- ---------- ----------&lt;br /&gt;         1                   192&lt;br /&gt;         1          1        210&lt;br /&gt;         1          2         90&lt;br /&gt;         1          3        120&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-114655311733839842?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/114655311733839842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=114655311733839842' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114655311733839842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114655311733839842'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/05/one-row-goes-to-two-groups.html' title='One row goes to two groups'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-114559656802368716</id><published>2006-04-20T22:08:00.000-07:00</published><updated>2006-04-20T22:16:08.036-07:00</updated><title type='text'>get database parameter</title><content type='html'>You do not need to have DBA priviledge to view all the database parameters&lt;br /&gt;&lt;br /&gt;A simple script will do&lt;br /&gt;&lt;br /&gt;set serveroutput on size 1000000&lt;br /&gt;&lt;br /&gt;declare  &lt;br /&gt;      x number;&lt;br /&gt;      y long;  &lt;br /&gt;      d number; &lt;br /&gt;begin         &lt;br /&gt;     if ( dbms_utility.get_parameter_value( '&amp;1', x, y ) = 1 )&lt;br /&gt;     then &lt;br /&gt;          dbms_output.put_line( y );&lt;br /&gt;     else &lt;br /&gt;         dbms_output.put_line( x );&lt;br /&gt;     end if;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;Unfortunately, the following parameters are not supported&lt;br /&gt;&lt;br /&gt;shared_pool_size&lt;br /&gt;sga_max_size&lt;br /&gt;shared_pool_reserved_size&lt;br /&gt;large_pool_size&lt;br /&gt;java_pool_size&lt;br /&gt;db_keep_cache_size&lt;br /&gt;db_recycle_cache_size&lt;br /&gt;db_2k_cache_size&lt;br /&gt;db_4k_cache_size&lt;br /&gt;db_8k_cache_size&lt;br /&gt;db_16k_cache_size&lt;br /&gt;db_32k_cache_size&lt;br /&gt;db_cache_size&lt;br /&gt;pga_aggregate_target&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-114559656802368716?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/114559656802368716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=114559656802368716' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114559656802368716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114559656802368716'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/04/get-database-parameter.html' title='get database parameter'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-114491537248513926</id><published>2006-04-13T00:59:00.000-07:00</published><updated>2006-04-13T01:02:52.503-07:00</updated><title type='text'>Join Methods</title><content type='html'>Abstracted from Oracle Online Document&lt;br /&gt;&lt;a href="http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96533/optimops.htm#56299"&gt;http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96533/optimops.htm#56299&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;1. Nested Loop&lt;br /&gt;&lt;br /&gt;The optimizer uses nested loop joins when joining small number of rows, with a good driving condition between the two tables. You drive from the outer loop to the inner loop, so the order of tables in the execution plan is important.&lt;a name="49598"&gt;&lt;/a&gt;&lt;br /&gt;The outer loop is the driving row source. It produces a set of rows for driving the join condition. The row source can be a table accessed using an index scan or a full table scan. Also, the rows can be produced from any other operation. For example, the output from a nested loop join can be used as a row source for another nested loop join.&lt;a name="49599"&gt;&lt;/a&gt;&lt;br /&gt;The inner loop is iterated for every row returned from the outer loop, ideally by an index scan. If the access path for the inner loop is not dependent on the outer loop, then you can end up with a Cartesian product; for every iteration of the outer loop, the inner loop produces the same set of rows. Therefore, you should use other join methods when two independent row sources are joined together.&lt;br /&gt;&lt;br /&gt;2. Hash Join&lt;br /&gt;&lt;br /&gt;The optimizer uses a hash join to join two tables if they are joined using an equijoin and if either of the following conditions are true:&lt;br /&gt;&lt;a name="49938"&gt;&lt;/a&gt;A large amount of data needs to be joined.&lt;br /&gt;&lt;a name="49939"&gt;&lt;/a&gt;A large fraction of the table needs to be joined.&lt;br /&gt;&lt;br /&gt;(Note: The smaller one will be used to build the in-memory hash)&lt;br /&gt;&lt;br /&gt;3. Sort Merge&lt;br /&gt;&lt;br /&gt;The optimizer can choose a sort merge join over a hash join for joining large amounts of data if any of the following conditions are true:&lt;br /&gt;&lt;a name="71720"&gt;&lt;/a&gt;The join condition between two tables is not an equi-join.&lt;br /&gt;&lt;a name="71721"&gt;&lt;/a&gt;OPTIMIZER_MODE is set to RULE.&lt;br /&gt;&lt;a name="71722"&gt;&lt;/a&gt;HASH_JOIN_ENABLED is false.&lt;br /&gt;&lt;a name="71723"&gt;&lt;/a&gt;Because of sorts already required by other operations, the optimizer finds it is cheaper to use a sort merge than a hash join.&lt;br /&gt;&lt;a name="71724"&gt;&lt;/a&gt;The optimizer thinks that the cost of a hash join is higher, based on the settings of HASH_AREA_SIZE and SORT_AREA_SIZE.&lt;br /&gt;&lt;br /&gt;Note: &lt;a name="71728"&gt;&lt;/a&gt;&lt;br /&gt;Oracle does not recommend using the HASH_AREA_SIZE and SORT_AREA_SIZE parameters unless the instance is configured with the shared server option. Oracle recommends instead that you enable automatic sizing of SQL work areas by setting PGA_AGGREGATE_TARGET. HASH_AREA_SIZE and SORT_AREA_SIZE are retained only for backward compatibility.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-114491537248513926?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/114491537248513926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=114491537248513926' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114491537248513926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114491537248513926'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/04/join-methods.html' title='Join Methods'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-114411334173956277</id><published>2006-04-03T18:08:00.000-07:00</published><updated>2006-05-10T23:14:41.850-07:00</updated><title type='text'>Reverse a multi-byte string</title><content type='html'>reverse() reverses a single byte string but it does not work well with multi-byte characters&lt;br /&gt;&lt;br /&gt;SQL&gt; select reverse('abc') from dual;&lt;br /&gt;REVERS&lt;br /&gt;------&lt;br /&gt;cba&lt;br /&gt;&lt;br /&gt;SQL&gt; exec :mystr := '国中cba';&lt;br /&gt;1 SELECT max(replace(SYS_CONNECT_BY_PATH (c, '/'), '/')) keep (dense_rank last order by level)&lt;br /&gt;2 FROM (SELECT LEVEL lvl, SUBSTR (:mystr, LEVEL, 1) c&lt;br /&gt;3 FROM (SELECT LENGTH (:mystr) len&lt;br /&gt;4 FROM DUAL) x&lt;br /&gt;5 CONNECT BY LEVEL &lt;= x.len&lt;br /&gt;6 ORDER BY 1 DESC)&lt;br /&gt;7* CONNECT BY PRIOR lvl = lvl + 1&lt;br /&gt;&lt;br /&gt;MAX(REPLACE(SYS_CONNECT_BY_PATH(C,'/'),'/'))KEEP(DENSE_RANKLASTORDERBYLEVEL)&lt;br /&gt;----------------------------------------------------------------------------&lt;br /&gt;abc中国&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-114411334173956277?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/114411334173956277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=114411334173956277' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114411334173956277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114411334173956277'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/04/reverse-multi-byte-string.html' title='Reverse a multi-byte string'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-114367834844113551</id><published>2006-03-29T16:23:00.000-08:00</published><updated>2006-03-29T16:25:48.453-08:00</updated><title type='text'>Find rows containing multi-byte character</title><content type='html'>select *&lt;br /&gt;from&lt;br /&gt;you_table&lt;br /&gt;where length(your_column) &lt;&gt; lengthb(your_column)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-114367834844113551?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/114367834844113551/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=114367834844113551' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114367834844113551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114367834844113551'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/03/find-rows-containing-multi-byte.html' title='Find rows containing multi-byte character'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-114350792542921094</id><published>2006-03-27T17:03:00.000-08:00</published><updated>2006-03-27T17:05:25.450-08:00</updated><title type='text'>Passing a select as Cursor to a Function</title><content type='html'>create or replace function CursorSum(cur SYS_REFCURSOR) return number&lt;br /&gt;AS&lt;br /&gt;    ln_int NUMBER;&lt;br /&gt;    ln_sum NUMBER := 0;&lt;br /&gt;BEGIN&lt;br /&gt;    loop&lt;br /&gt;        fetch cur into ln_int;&lt;br /&gt;        exit when cur%NOTFOUND;&lt;br /&gt;        ln_sum := ln_sum + ln_int;&lt;br /&gt;    end loop;&lt;br /&gt;    return ln_sum;&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;select CursorSum(Cursor(select 10 from dual union all select 20 from dual)) as sum&lt;br /&gt;from dual&lt;br /&gt;&lt;br /&gt;  SUM&lt;br /&gt;-----&lt;br /&gt;   30&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-114350792542921094?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/114350792542921094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=114350792542921094' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114350792542921094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114350792542921094'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/03/passing-select-as-cursor-to-function.html' title='Passing a select as Cursor to a Function'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-114350691116445595</id><published>2006-03-27T16:34:00.000-08:00</published><updated>2006-03-27T16:48:31.176-08:00</updated><title type='text'>Select from a function</title><content type='html'>The following steps allow you select from a function return value just like a normal table.&lt;br /&gt;&lt;br /&gt;1. Create a record type&lt;br /&gt;&lt;br /&gt;Create TYPE MyRecType AS OBJECT&lt;br /&gt;(c1 number, c2 varchar2(5));&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;2. Create a table type&lt;br /&gt;&lt;br /&gt;Create Type MyTabType AS Table of MyRecType;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;3. Create a function returning the Table Type&lt;br /&gt;&lt;br /&gt;Create or Replace function MyFunc return MyTabType&lt;br /&gt;AS&lt;br /&gt;   mytab MyTabType := MyTabType();&lt;br /&gt;BEGIN&lt;br /&gt;   mytab.extend(2);&lt;br /&gt;   mytab(1) := MyRecType(1, 'abc');&lt;br /&gt;   mytab(2) := myRecType(2, 'efg');&lt;br /&gt;   return mytab;&lt;br /&gt;END;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;4. Do you select&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from TABLE(MyFunc);&lt;br /&gt;&lt;br /&gt;        C1 C2&lt;br /&gt;---------- --------------------&lt;br /&gt;         1 abc&lt;br /&gt;         2 efg&lt;br /&gt;&lt;br /&gt;** Note **&lt;br /&gt;You can make the function as PIPELINE (refer to Oracle Docs for details)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-114350691116445595?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/114350691116445595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=114350691116445595' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114350691116445595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114350691116445595'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/03/select-from-function.html' title='Select from a function'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-114350597396032797</id><published>2006-03-27T16:15:00.000-08:00</published><updated>2006-03-27T16:32:53.976-08:00</updated><title type='text'>get one line randomly from a group</title><content type='html'>SQL&gt; select c1, c2&lt;br /&gt;  2  from x;&lt;br /&gt;&lt;br /&gt;C1    C2&lt;br /&gt;----- ------------&lt;br /&gt;1     a&lt;br /&gt;1     b&lt;br /&gt;1     c&lt;br /&gt;2     a&lt;br /&gt;2     c&lt;br /&gt;3     f&lt;br /&gt;4     c&lt;br /&gt;5     a&lt;br /&gt;&lt;br /&gt;SQL&gt; select&lt;br /&gt;  2     c1,&lt;br /&gt;  3     substr(max(dbms_random.string('a', 1) || c2), 2) random_c2&lt;br /&gt;  4  from x&lt;br /&gt;  5  group by c1&lt;br /&gt;  6  /&lt;br /&gt;&lt;br /&gt;C1    RANDOM_C2&lt;br /&gt;----- --------------------&lt;br /&gt;1     b&lt;br /&gt;3     f&lt;br /&gt;5     a&lt;br /&gt;2     a&lt;br /&gt;4     c&lt;br /&gt;&lt;br /&gt;Or you can do it with a fancy way&lt;br /&gt;  1  select c1,&lt;br /&gt;  2  min(c2) keep (dense_rank first order by dbms_random.value) random_c2&lt;br /&gt;  3  from x&lt;br /&gt;  4  group by c1&lt;br /&gt;  5* order by 1&lt;br /&gt;&lt;br /&gt;C1                   RANDO&lt;br /&gt;-------------------- -----&lt;br /&gt;1                    a&lt;br /&gt;2                    c&lt;br /&gt;3                    f&lt;br /&gt;4                    c&lt;br /&gt;5                    a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-114350597396032797?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/114350597396032797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=114350597396032797' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114350597396032797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/114350597396032797'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/03/get-one-line-randomly-from-group.html' title='get one line randomly from a group'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-113989633715173670</id><published>2006-02-13T21:47:00.000-08:00</published><updated>2006-02-13T21:52:17.160-08:00</updated><title type='text'>Transpose rows into columns</title><content type='html'>TABLE EMP_B&lt;br /&gt;EMP_ID/EMP_NAME&lt;br /&gt; &lt;br /&gt;111/TEST RARO/ &lt;br /&gt;112/ICHIGO MUJIKO&lt;br /&gt;113/NORISHIMA ICHIRO&lt;br /&gt;…&lt;br /&gt;&lt;br /&gt;Table EMP_PHONE&lt;br /&gt;(One employee may have up to 3 types of phone numbers, Type 1 – home, type2 – office and type 3 - cell)&lt;br /&gt;&lt;br /&gt;EMP_ID/TYPE/PHONE NUMBER&lt;br /&gt; &lt;br /&gt;111/1/037378877987&lt;br /&gt;111/2/048880000078&lt;br /&gt;112/1/034878887888&lt;br /&gt;112/2/044545645878&lt;br /&gt;112/3/090945564456&lt;br /&gt;114/1/456777899889&lt;br /&gt;&lt;br /&gt;With the following query, you can get all the phone number into one row for one employee&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECT a.emp_id, &lt;br /&gt;a.                      emp_name, &lt;br /&gt;NVL(b.phone1, ‘NA’) phone_1, &lt;br /&gt;NVL(b.phone2, ‘NA’) phone_2, &lt;br /&gt;NVL(b.phone3, ‘NA’) phone_3&lt;br /&gt;FROM&lt;br /&gt;    EMP_B a,&lt;br /&gt;    (SELECT EMP_ID&lt;br /&gt; MIN(DECODE(TYPE, 1, PHONE_NUMBER, NULL)) PHONE1,&lt;br /&gt; MIN(DECODE(TYPE, 2, PHONE_NUMBER, NULL)) PHONE2,&lt;br /&gt; MIN(DECODE(TYPE, 3, PHONE_NUMBER, NULL)) PHONE3&lt;br /&gt;     FROM EMP_PHONE&lt;br /&gt;    GROUP BY EMP_ID) b&lt;br /&gt;WHERE a.emp_id = b.emp_id (+)&lt;br /&gt;&lt;br /&gt;The result will be&lt;br /&gt;&lt;br /&gt;EMP_ID     EMP_NAME         PHONE_1    PHONE_2    PHONE_3&lt;br /&gt;&lt;br /&gt;111   TEST_RARO        037378877987 048880000078  NA&lt;br /&gt;112   ICHIGO_MUJIKO       034878887888 044545645878  90945564456&lt;br /&gt;113   NORISHIMA ICHIRO     NA           NA            NA&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-113989633715173670?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/113989633715173670/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=113989633715173670' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113989633715173670'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113989633715173670'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/02/transpose-rows-into-columns.html' title='Transpose rows into columns'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-113981497121013581</id><published>2006-02-12T23:14:00.000-08:00</published><updated>2006-02-12T23:16:11.210-08:00</updated><title type='text'>Strip out the number from a string</title><content type='html'>select result&lt;br /&gt;from&lt;br /&gt;(&lt;br /&gt;select level, replace(sys_connect_by_path(x, '/'), '/') result&lt;br /&gt;from&lt;br /&gt;(select rownum lvl, x from (select level lvl, substr('&lt;strong&gt;XYZabcd1234.34efEFGgh&lt;/strong&gt;', level, 1) x&lt;br /&gt;from dual connect by 1 = 1 and level &lt;= length('&lt;strong&gt;XYZabcd1234.34efEFGgh&lt;/strong&gt;'))&lt;br /&gt;where x between '0' and '9' or x = '.')&lt;br /&gt;connect by prior lvl = lvl -1&lt;br /&gt;start with lvl = 1&lt;br /&gt;order by level desc&lt;br /&gt;)&lt;br /&gt;where rownum &lt; 2&lt;br /&gt;&lt;br /&gt;RESULT&lt;br /&gt;---------&lt;br /&gt;1234.34&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-113981497121013581?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/113981497121013581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=113981497121013581' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113981497121013581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113981497121013581'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/02/strip-out-number-from-string.html' title='Strip out the number from a string'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-113981427486630759</id><published>2006-02-12T23:01:00.000-08:00</published><updated>2006-02-12T23:04:34.866-08:00</updated><title type='text'>Count String Occurance</title><content type='html'>(length(str1) - length(replace(str1, str2)))/length(str2)&lt;br /&gt;gives how many times str2 appears in str1.&lt;br /&gt;&lt;br /&gt;e.g.&lt;br /&gt;&lt;br /&gt;select (length('xyzabc123abcefgh') - length(replace('xyzabc123abcefgh', 'abc')))/length('abc') from dual&lt;br /&gt;&lt;br /&gt; OCCURANCE&lt;br /&gt;----------&lt;br /&gt;         2&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-113981427486630759?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/113981427486630759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=113981427486630759' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113981427486630759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113981427486630759'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/02/count-string-occurance.html' title='Count String Occurance'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-113981398103274840</id><published>2006-02-12T22:57:00.000-08:00</published><updated>2006-02-12T23:07:01.283-08:00</updated><title type='text'>split a string into multiple lines by comma</title><content type='html'>SQL&gt; select c2 from test;&lt;br /&gt;&lt;br /&gt;C2&lt;br /&gt;----------------------------------------&lt;br /&gt;a,b,c,dd,efg&lt;br /&gt;h,iii&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;select &lt;br /&gt;decode(lvl, 1, substr(c2, 1, instr(c2, ',', 1) - 1),&lt;br /&gt;length(c2) - length(replace(c2, ',')) + 1, substr(c2, instr(c2, ',', 1, lvl-1)+1),&lt;br /&gt;substr(c2, instr(c2, ',', 1, lvl-1) + 1, instr(c2, ',', 1, lvl) - instr(c2, ',', 1, lvl-1) -1)) &lt;br /&gt;what_you_need&lt;br /&gt;from&lt;br /&gt;(&lt;br /&gt;select level lvl from (select max(length(c2) - length(replace(c2, ','))) + 1 maxlvl from test)&lt;br /&gt;connect by 1 = 1 and level &lt;= maxlvl&lt;br /&gt;),&lt;br /&gt;test&lt;br /&gt;where lvl &lt; length(c2) - length(replace(c2, ',')) + 2&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;WHAT_YOU_NEED&lt;br /&gt;-------------&lt;br /&gt;a&lt;br /&gt;b&lt;br /&gt;c&lt;br /&gt;dd&lt;br /&gt;efg&lt;br /&gt;h&lt;br /&gt;iii&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-113981398103274840?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/113981398103274840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=113981398103274840' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113981398103274840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113981398103274840'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/02/split-string-into-multiple-lines-by.html' title='split a string into multiple lines by comma'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-113981358335979350</id><published>2006-02-12T22:51:00.000-08:00</published><updated>2006-02-12T22:53:03.360-08:00</updated><title type='text'>Group by continuous date range</title><content type='html'>SQL&gt; select * from sales order by 1;&lt;br /&gt;&lt;br /&gt;EVENT_TIME                  AMT&lt;br /&gt;-------------------- ----------&lt;br /&gt;06-01-18                     62&lt;br /&gt;06-01-19                     43&lt;br /&gt;06-01-20                     18&lt;br /&gt;06-01-22                      5&lt;br /&gt;06-01-23                     94&lt;br /&gt;06-01-24                     34&lt;br /&gt;06-01-25                     88&lt;br /&gt;06-01-26                     57&lt;br /&gt;06-01-27                      5&lt;br /&gt;06-01-30                     72&lt;br /&gt;06-01-31                     96&lt;br /&gt;06-02-01                      5&lt;br /&gt;06-02-04                     43&lt;br /&gt;&lt;br /&gt;SQL&gt; with x as (&lt;br /&gt;  2  select * from sales order by 1 asc&lt;br /&gt;  3  )&lt;br /&gt;  4  select min(event_time) Start_date, max(event_time) End_date, sum(amt) Amount&lt;br /&gt;  5  from x&lt;br /&gt;  6  group by event_time - rownum&lt;br /&gt;  7  order by 1&lt;br /&gt;  8  /&lt;br /&gt;&lt;br /&gt;START_DA END_DATE     AMOUNT&lt;br /&gt;-------- -------- ----------&lt;br /&gt;06-01-18 06-01-20        123&lt;br /&gt;06-01-22 06-01-27        283&lt;br /&gt;06-01-30 06-02-01        173&lt;br /&gt;06-02-04 06-02-04         43&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-113981358335979350?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/113981358335979350/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=113981358335979350' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113981358335979350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113981358335979350'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/02/group-by-continuous-date-range.html' title='Group by continuous date range'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-113967415822162310</id><published>2006-02-11T07:48:00.000-08:00</published><updated>2006-02-11T08:09:18.246-08:00</updated><title type='text'>Generate continuous data</title><content type='html'>See, if you have a sales table like&lt;br /&gt;&lt;br /&gt;SDATE             AMT&lt;br /&gt;---------- ----------&lt;br /&gt;02/01/2006         34&lt;br /&gt;02/02/2006         60&lt;br /&gt;02/04/2006         35&lt;br /&gt;02/05/2006         53&lt;br /&gt;02/07/2006         61&lt;br /&gt;02/08/2006         23&lt;br /&gt;02/09/2006         34&lt;br /&gt;02/10/2006         34&lt;br /&gt;&lt;br /&gt;The data is not continuous but your employer needs a continuous&lt;br /&gt;report over the whole data range 02/01/2006 - 02/10/2006&lt;br /&gt;&lt;br /&gt;Here comes the solution&lt;br /&gt;&lt;br /&gt;SQL&gt; r&lt;br /&gt;  1  with dates as (&lt;br /&gt;  2  select trunc(sysdate, 'MM') + level - 1 sdate&lt;br /&gt;  3  from dual connect by level &lt;= 10)&lt;br /&gt;  4  select dates.sdate, nvl(sales.amt, 0) amt&lt;br /&gt;  5  from dates, sales&lt;br /&gt;  6* where sales.sdate (+) = dates.sdate&lt;br /&gt;&lt;br /&gt;SDATE             AMT&lt;br /&gt;---------- ----------&lt;br /&gt;02/01/2006         34&lt;br /&gt;02/02/2006         60&lt;br /&gt;02/03/2006          0&lt;br /&gt;02/04/2006         35&lt;br /&gt;02/05/2006         53&lt;br /&gt;02/06/2006          0&lt;br /&gt;02/07/2006         61&lt;br /&gt;02/08/2006         23&lt;br /&gt;02/09/2006         34&lt;br /&gt;02/10/2006         34&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-113967415822162310?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/113967415822162310/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=113967415822162310' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113967415822162310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113967415822162310'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/02/generate-continuous-data.html' title='Generate continuous data'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22250741.post-113958263142793147</id><published>2006-02-10T06:42:00.000-08:00</published><updated>2006-02-10T07:37:11.306-08:00</updated><title type='text'>Loop</title><content type='html'>No doubt, most important features in any computer languages are condition (if statement) and loop.&lt;br /&gt;&lt;br /&gt;In SQL, we have decode/case to do conditional check. To do a loop, before Oracle 9i, it was a no-go; now, you can have something like&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT rownum FROM (SELECT * FROM DUAL CONNECT BY LEVEL &lt;= 10);&lt;br /&gt;&lt;br /&gt;    ROWNUM&lt;br /&gt;----------&lt;br /&gt;         1&lt;br /&gt;         2&lt;br /&gt;         3&lt;br /&gt;         4&lt;br /&gt;         5&lt;br /&gt;         6&lt;br /&gt;         7&lt;br /&gt;         8&lt;br /&gt;         9&lt;br /&gt;        10&lt;br /&gt;&lt;br /&gt;10 rows selected.&lt;br /&gt;&lt;br /&gt;Simple? Ok, let's have some fun&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from x;&lt;br /&gt;&lt;br /&gt;C1 C2&lt;br /&gt;---------- ----------&lt;br /&gt;11111 1&lt;br /&gt;22222 2&lt;br /&gt;33333 3&lt;br /&gt;44444 4&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; create table y (c1 number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; insert into y&lt;br /&gt;2 select a.c1 from x a,&lt;br /&gt;3 (&lt;br /&gt;4 select rownum rn from (select max(c2) maxlevel from x) a connect by 1=1 and level &lt;=&lt;br /&gt;5 maxlevel) b&lt;br /&gt;6 where a.c2 &gt;= rn&lt;br /&gt;7 order by c1&lt;br /&gt;8 /&lt;br /&gt;&lt;br /&gt;10 rows created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from y;&lt;br /&gt;&lt;br /&gt;C1&lt;br /&gt;----------&lt;br /&gt;11111&lt;br /&gt;22222&lt;br /&gt;22222&lt;br /&gt;33333&lt;br /&gt;33333&lt;br /&gt;33333&lt;br /&gt;44444&lt;br /&gt;44444&lt;br /&gt;44444&lt;br /&gt;44444&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/22250741-113958263142793147?l=sqlmagic.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlmagic.blogspot.com/feeds/113958263142793147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=22250741&amp;postID=113958263142793147' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113958263142793147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/22250741/posts/default/113958263142793147'/><link rel='alternate' type='text/html' href='http://sqlmagic.blogspot.com/2006/02/loop.html' title='Loop'/><author><name>Huiming Li</name><uri>http://www.blogger.com/profile/00360855688927098569</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
