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

<channel>
	<title>An Oracle blog - Amardeep Sidhu &#187; SQL</title>
	<atom:link href="http://amardeepsidhu.com/blog/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://amardeepsidhu.com/blog</link>
	<description>Little bit of fun with Oracle and the related technologies...</description>
	<lastBuildDate>Thu, 22 Dec 2011 05:59:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Delete Delete Faster Faster ;)</title>
		<link>http://amardeepsidhu.com/blog/2009/10/08/delete-delete-faster-faster/</link>
		<comments>http://amardeepsidhu.com/blog/2009/10/08/delete-delete-faster-faster/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 15:23:36 +0000</pubDate>
		<dc:creator>Sidhu</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Delete]]></category>

		<guid isPermaLink="false">http://amardeepsidhu.com/blog/?p=266</guid>
		<description><![CDATA[2-3 days ago, I came across a code, intended to make delete faster. Just have a look<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2009/10/08/delete-delete-faster-faster/' addthis:title='Delete Delete Faster Faster ;) '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>2-3 days ago, I came across a code, intended to make delete faster. Just have a look <img src='http://amardeepsidhu.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre class="brush: sql; title: ; notranslate">.
.
.
LOOP
SELECT COUNT (1)
INTO v_cnt
FROM table1
WHERE ROWNUM &lt; 2;

IF v_cnt = 0
THEN
EXIT;
END IF;

DELETE FROM table1
WHERE ROWNUM &lt; 1000;

COMMIT;
v_cnt := 0;
END LOOP;
.
.
.</pre>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2009/10/08/delete-delete-faster-faster/' addthis:title='Delete Delete Faster Faster ;) '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://amardeepsidhu.com/blog/2009/10/08/delete-delete-faster-faster/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Missing grants</title>
		<link>http://amardeepsidhu.com/blog/2008/03/03/missing-grants/</link>
		<comments>http://amardeepsidhu.com/blog/2008/03/03/missing-grants/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 15:07:15 +0000</pubDate>
		<dc:creator>Sidhu</dc:creator>
				<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://amardeepsidhu.com/blog/2008/03/03/missing-grants/</guid>
		<description><![CDATA[Today one of my colleague was working on a simple PL/SQL procedure. Based on some logic it was returning count(*) from all_tab_columns for few tables. It gave count incorrectly for one table out of around fifty in total. He just hard coded the table name and ran it but again it showed count as zero. [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2008/03/03/missing-grants/' addthis:title='Missing grants '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Today one of my colleague was working on a simple PL/SQL procedure. Based on some logic it was returning count(*) from all_tab_columns for few tables. It gave count incorrectly for one table out of around fifty in total. He just hard coded the table name and ran it but again it showed count as zero.</p>
<p>Then he took the code out of procedure and wrote it in DECLARE, BEGIN, END and after running it showed the correct count. But ran as database procedure it always shows incorrectly.</p>
<p>Finally just as hit and trial, he gave SELECT on the TABLE to database user [Table was in different schema], used to run the procedure and everything was ok. Isn&#8217;t it bit stupid <img src='http://amardeepsidhu.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Update:</strong> Well, it happens for a reason. <a href="http://preferisco.blogspot.com/">Nigel Thomas</a> pointed out in the comment. The reason is that privileges granted to a role are not seen from PL/SQL stored procedures. You need to give direct grant to the user for this or another method is to define the procedure or package with invoker rights.</p>
<p>Thanks Nigel <img src='http://amardeepsidhu.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2008/03/03/missing-grants/' addthis:title='Missing grants '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://amardeepsidhu.com/blog/2008/03/03/missing-grants/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Learning Regular Expressions</title>
		<link>http://amardeepsidhu.com/blog/2008/02/27/learning-regular-expressions/</link>
		<comments>http://amardeepsidhu.com/blog/2008/02/27/learning-regular-expressions/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 15:59:50 +0000</pubDate>
		<dc:creator>Sidhu</dc:creator>
				<category><![CDATA[Oracle Basics]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://amardeepsidhu.com/blog/2008/02/27/learning-regular-expressions/</guid>
		<description><![CDATA[From Eddie&#8217;s blog I got a link to 3 posts on Regular Expressions on OTN written by CD. Wonderful stuff. Check out. Part 1 Part 2 Part 3 &#38; Thanks CD&#8230;wonderful work buddy !<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2008/02/27/learning-regular-expressions/' addthis:title='Learning Regular Expressions '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://awads.net/wp/2008/02/25/5-useful-links-for-2008-02-25/" title="Eddie's blog" target="_blank">Eddie&#8217;s blog</a> I got a link to 3 posts on Regular Expressions on OTN written by <a href="http://www.l2is.com/apex/f?p=999:3:3754894570320873::NO::P3_NAME:ARTICLE46" title="CD's blog" target="_blank">CD</a>. Wonderful stuff. Check out.</p>
<p><a href="http://forums.oracle.com/forums/thread.jspa?threadID=427716" title="Part 1" target="_blank">Part 1</a></p>
<p><a href="http://forums.oracle.com/forums/thread.jspa?threadID=430647" title="Part 2" target="_blank">Part 2</a></p>
<p><a href="http://forums.oracle.com/forums/thread.jspa?threadID=435109" title="Part 3" target="_blank">Part 3</a></p>
<p>&amp; Thanks CD&#8230;wonderful work buddy !</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2008/02/27/learning-regular-expressions/' addthis:title='Learning Regular Expressions '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://amardeepsidhu.com/blog/2008/02/27/learning-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Shell script to spool a no of tables into .xls files&#8230;</title>
		<link>http://amardeepsidhu.com/blog/2007/06/26/shell-script-to-spool-a-no-of-tables-into-xls-files/</link>
		<comments>http://amardeepsidhu.com/blog/2007/06/26/shell-script-to-spool-a-no-of-tables-into-xls-files/#comments</comments>
		<pubDate>Tue, 26 Jun 2007 17:08:00 +0000</pubDate>
		<dc:creator>Sidhu</dc:creator>
				<category><![CDATA[Oracle Tips]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://amardeepsidhu.com/blog/?p=25</guid>
		<description><![CDATA[On OTN someone asked a question that how to spool data from a table into a xls file. Spooling a single table I discussed in one of the previous posts. We can use the same approach to spool data from more than 1 table also. Well here I will do it through a shell script [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2007/06/26/shell-script-to-spool-a-no-of-tables-into-xls-files/' addthis:title='Shell script to spool a no of tables into .xls files&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>On OTN someone asked <a href="http://forums.oracle.com/forums/thread.jspa?threadID=523835&amp;tstart=50">a question</a> that how to spool data from a table into a xls file. Spooling a single table I discussed in one of the <a href="http://amardeepsidhu.com/blog/2007/06/16/spool-to-a-xls-excel-file">previous posts</a>. We can use the same approach to spool data from more than 1 table also. Well here I will do it through a shell script and assume that you have a text file having list of tables to be spooled (Even if you don&#8217;t have one, it can be easily made by spooling the names of tables into a simple text file) Here is the shell script that you can use to spool data to various xls files, table wise.</p>
<pre class="brush: css; title: ; notranslate">cat list.txt | while read a
do
echo &quot;spooling $a&quot;
sqlplus username/password@string &amp;lt;&amp;lt;EOF
set feed off markup html on spool on
spool /home/oracle/$a.xls
select * from $a;
spool off
set markup html off spool off
EOF
done
</pre>
<p>I didn&#8217;t see any work around for Windoze as SQLPLUS &lt;&lt; EOF thing doesn&#8217;t seem to work in Windows. Will try to find some alternative. If you come across something, do let me know.</p>
<p>Sidhu</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2007/06/26/shell-script-to-spool-a-no-of-tables-into-xls-files/' addthis:title='Shell script to spool a no of tables into .xls files&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://amardeepsidhu.com/blog/2007/06/26/shell-script-to-spool-a-no-of-tables-into-xls-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Spool to a .xls (excel) file&#8230;</title>
		<link>http://amardeepsidhu.com/blog/2007/06/16/spool-to-a-xls-excel-file/</link>
		<comments>http://amardeepsidhu.com/blog/2007/06/16/spool-to-a-xls-excel-file/#comments</comments>
		<pubDate>Fri, 15 Jun 2007 18:44:00 +0000</pubDate>
		<dc:creator>Sidhu</dc:creator>
				<category><![CDATA[Oracle Tips]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[spool to excel]]></category>

		<guid isPermaLink="false">http://amardeepsidhu.com/blog/?p=22</guid>
		<description><![CDATA[A small tip, I read on OTN about spooling to a .xls (excel) file: It goes like this And the xls it makes shows up like: Sidhu<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2007/06/16/spool-to-a-xls-excel-file/' addthis:title='Spool to a .xls (excel) file&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>A small tip, I read on <a href="http://forums.oracle.com/forums/thread.jspa?messageID=1849526">OTN</a> about spooling to a .xls (excel) file:</p>
<p>It goes like this</p>
<pre class="brush: css; title: ; notranslate">set feed off markup html on
spool onspool c:\salgrade.xls
select * from salgrade;
spool offset markup html off
spool off</pre>
<p>And the xls it makes shows up like:</p>
<pre><a href="http://bp2.blogger.com/_cX21i_8-MT4/RnLaSNXaVrI/AAAAAAAAACM/nxm6jQbYTak/s1600-h/xls.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5076359736360326834" style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer" src="http://bp2.blogger.com/_cX21i_8-MT4/RnLaSNXaVrI/AAAAAAAAACM/nxm6jQbYTak/s320/xls.JPG" border="0" alt="" /></a></pre>
<p><img src="file:///C:/DOCUME%7E1/Amardeep/LOCALS%7E1/Temp/moz-screenshot.jpg" alt="" />Sidhu</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2007/06/16/spool-to-a-xls-excel-file/' addthis:title='Spool to a .xls (excel) file&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://amardeepsidhu.com/blog/2007/06/16/spool-to-a-xls-excel-file/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Command line history in SQL (for Linux)&#8230;</title>
		<link>http://amardeepsidhu.com/blog/2007/05/04/command-line-history-in-sql-for-linux/</link>
		<comments>http://amardeepsidhu.com/blog/2007/05/04/command-line-history-in-sql-for-linux/#comments</comments>
		<pubDate>Fri, 04 May 2007 15:05:00 +0000</pubDate>
		<dc:creator>Sidhu</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[rlwrap]]></category>

		<guid isPermaLink="false">http://amardeepsidhu.com/blog/?p=14</guid>
		<description><![CDATA[Found a very interesting article on Dizwell&#8217;s blog. It was about keeping history of the SQL commands in SQL Plus on Linux. It is almost very simple. Just need to download a small utility called rlwrap from here. Its a tar.gz file. Download it, un-tar using It will create a directory with the same name. [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2007/05/04/command-line-history-in-sql-for-linux/' addthis:title='Command line history in SQL (for Linux)&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Found a very interesting article on Dizwell&#8217;s blog. It was about keeping history of the SQL commands in SQL Plus on Linux. It is almost very simple. Just need to download a small utility called rlwrap from <a href="http://utopia.knoware.nl/%7Ehlub/rlwrap/">here</a>. Its a tar.gz file. Download it, un-tar using</p>
<pre class="brush: css; title: ; notranslate">
tar -xvf rlwrap-0.28.tar.gz
</pre>
<p>It will create a directory with the same name. <span style="font-weight: bold">cd</span> to the directory and run</p>
<pre class="brush: css; title: ; notranslate">
./configure
</pre>
<p>Now do</p>
<pre class="brush: css; title: ; notranslate">
make install
</pre>
<p>(I was logged in as <span style="font-weight: bold">oracle </span>user, then did <span style="font-weight: bold">su, </span>but it gave some errors, finally I logged in as root and it worked fine)</p>
<p>Now what is left to be done is make an alias for sqlplus as</p>
<pre class="brush: css; title: ; notranslate">
alias sqlplus='rlwrap sqlplus'
</pre>
<p>Using up/down arrows, commands can be scrolled up and down just like windows. Have a look at full article <a href="http://www.dizwell.com/prod/node/56">here</a>.</p>
<p>Cheers</p>
<p>Sidhu</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://amardeepsidhu.com/blog/2007/05/04/command-line-history-in-sql-for-linux/' addthis:title='Command line history in SQL (for Linux)&#8230; '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://amardeepsidhu.com/blog/2007/05/04/command-line-history-in-sql-for-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

