<?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>kwatog &#187; Oracle</title>
	<atom:link href="http://kwatog.com/category/blog/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://kwatog.com</link>
	<description>tech notes and general nonsense</description>
	<lastBuildDate>Thu, 29 Jul 2010 12:06:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Oracle IN : Maximum Number of Values</title>
		<link>http://kwatog.com/blog/oracle/oracle-in-maximum-number-of-values/</link>
		<comments>http://kwatog.com/blog/oracle/oracle-in-maximum-number-of-values/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 09:22:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=269</guid>
		<description><![CDATA[In case you wonder what it the maximum number of values you can put inside the IN condition, it is 1000 as of Oracle 9i. It is documented in the link below. http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96536/ch44.htm#288033. Example: SELECT * FROM emp WHERE emp_no IN(1,2,3,4,5......1000); I needed this because I was given a long list of values (around 500 [...]]]></description>
			<content:encoded><![CDATA[<p>In case you wonder what it the maximum number of values you can put inside the IN condition, it is <strong>1000 </strong>as of Oracle 9i. It is documented in the link below.<br />
<a href="http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96536/ch44.htm#288033">http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96536/ch44.htm#288033</a>.</p>
<p>Example:</p>
<p><code>SELECT * FROM emp<br />
WHERE emp_no IN(1,2,3,4,5......1000);</code></p>
<p>I needed this because I was given a long list of values (around 500 values) and I need to fetch records in a table using that data. It would be easy if I can insert it first into a temp table and then join. Unfortunately, I only have read rights on the database so I need to use the IN condition. But I got concerned because in Oracle 7 and 8i releases, the maximum number of values you can put inside IN is a maximum of 255 (one byte). </p>
<h3>Note:</h3>
<p>Take note that the IN(SUBQUERY) does not have limitations because that&#8217;s essentially a join.</p>
<p>Example:<br />
<code>SELECT * FROM emp<br />
WHERE emp_no IN(SELECT emp_no FROM dept_emp);</code></p>
<p>However as part of my <strong>best practices</strong>, I make sure that the results of the IN subquery is either one or none for optimal performance (not applicable in some instances). </p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/oracle-in-maximum-number-of-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable/Disable Bind Variable in SQL*Plus</title>
		<link>http://kwatog.com/blog/oracle/enable-disable-bind-variable-in-sqlplus/</link>
		<comments>http://kwatog.com/blog/oracle/enable-disable-bind-variable-in-sqlplus/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 14:44:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=215</guid>
		<description><![CDATA[As state in the title, this post is about turning off the bind variable in SQL*Plus. Actually, this is also applicable in PL/SQL Developer and Toad but I&#8217;ll be discussing more on SQL*Plus. You see, I have a problem wherein whenever I load my backup data (saved as insert statements) and there are ampersand (&#038;) [...]]]></description>
			<content:encoded><![CDATA[<p>As state in the title, this post is about turning off the bind variable in SQL*Plus. Actually, this is also applicable in PL/SQL Developer and Toad but I&#8217;ll be discussing more on SQL*Plus. You see, I have a problem wherein whenever I load my backup data (saved as insert statements) and there are ampersand (&#038;) or colon(:) somewhere in the script, SQL*Plus will ask me for an input. Of course, I don&#8217;t need that because as a backup, I want to load the data as it is. And when migrating 60MB or more, then it isn&#8217;t funny to update the query one by one. The good thing is, I don&#8217;t actually need to update the query because there&#8217;s an answer to my problem. And it&#8217;s pretty damn simple.</p>
<h3>Syntax</h3>
<p><code><br />
set define off<br />
</code></p>
<p>Oh yes, that&#8217;s just one line that will solve my misery. Well, it&#8217;s all about my ignorance. To turn back on, then do the opposite as below.</p>
<h3>Syntax</h3>
<p><code><br />
set define on<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/enable-disable-bind-variable-in-sqlplus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle WITH Clause  (Subquery Factoring)</title>
		<link>http://kwatog.com/blog/oracle/oracle-with-clause-subquery-factoring/</link>
		<comments>http://kwatog.com/blog/oracle/oracle-with-clause-subquery-factoring/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 11:48:57 +0000</pubDate>
		<dc:creator>kwatog</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[subquery optimization]]></category>
		<category><![CDATA[WITH]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=187</guid>
		<description><![CDATA[WITH clause was introduced in Oracle 9i to provide powerful new syntax for enhancing query performance. It optimizes query speed by eliminating redundant processing in complex queries. WITH Clause Syntax WITH alias_name -- alias for the aggregate_query AS (aggregate_query_here) SELECT... -- Beginning of the query main body It should be noted that multiple aggregate queries [...]]]></description>
			<content:encoded><![CDATA[<p>WITH clause was introduced in Oracle 9i to provide powerful new syntax for enhancing query performance. It optimizes query speed by eliminating redundant processing in complex queries. </p>
<h3>WITH Clause Syntax</h3>
<pre name="code" class="sql">
WITH
 alias_name         -- alias for the aggregate_query
AS
 (aggregate_query_here)
SELECT...            -- Beginning of the query main body
</pre>
<p>It should be noted that multiple aggregate queries can be defined in the WITH clause as below.</p>
<pre name="code" class="sql">
WITH
 alias_name1
AS
 (agg_query1) ,
 alias_name2
AS
 (agg_query2)
SELECT...
</pre>
<p>When using subquery factoring, think of the aggregate_query as an in-line view. Actually, it is a view but a temporary one. Instead of creating a permanent view accessible in the database, you are creating a temporary one exclusively used by your main query. </p>
<h3>Usage</h3>
<p>I primarily use this in creating adhoc queries, reports and extractions. Of course, you can just create a view to accomplish this task. However, there are times wherein you are not allowed to create additional objects in the database for one reason or another. In that case, this subquery optimization comes very handy. </p>
<h3>Caveat</h3>
<p>You can&#8217;t use this inside Oracle Forms. It also doesn&#8217;t work inside stored procedures or anything with PL/SQL in it. At least I&#8217;m talking about until 11g. </p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/oracle-with-clause-subquery-factoring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle CASE WHEN Statement</title>
		<link>http://kwatog.com/blog/oracle/oracle-case-when-statement/</link>
		<comments>http://kwatog.com/blog/oracle/oracle-case-when-statement/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 16:02:14 +0000</pubDate>
		<dc:creator>kwatog</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[10g]]></category>
		<category><![CDATA[11g]]></category>
		<category><![CDATA[9i]]></category>
		<category><![CDATA[case]]></category>
		<category><![CDATA[when]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=182</guid>
		<description><![CDATA[Another oracle sql statement that you may need in order to simplify and optimize your code is the use of CASE statement. Here&#8217;s how it is being used. Syntax #1 CASE [ expression ] WHEN condition_1 THEN result_1 WHEN condition_2 THEN result_2 ... WHEN condition_n THEN result_n ELSE result END Example SELECT last_name, commission_pct, (CASE [...]]]></description>
			<content:encoded><![CDATA[<p>Another oracle sql statement that you may need in order to simplify and optimize your code is the use of CASE statement. Here&#8217;s how it is being used. </p>
<h3>Syntax #1</h3>
<p><code><br />
CASE  [ expression ]<br />
  WHEN condition_1 THEN result_1<br />
  WHEN condition_2 THEN result_2<br />
  ...<br />
  WHEN condition_n THEN result_n<br />
  ELSE result<br />
END<br />
</code></p>
<h3>Example</h3>
<p><code><br />
SELECT last_name, commission_pct,<br />
  (CASE commission_pct<br />
    WHEN 0.1 THEN ‘Low’<br />
    WHEN 0.15 THEN ‘Average’<br />
    WHEN 0.2 THEN ‘High’<br />
    ELSE ‘N/A’<br />
  END ) Commission<br />
FROM employees ORDER BY last_name;<br />
</code></p>
<h3>Syntax #2</h3>
<p><code><br />
CASE<br />
  WHEN [ condition_1 ] THEN result_1<br />
  WHEN [ condition_2 ] THEN result_2<br />
  ...<br />
  WHEN [ condition_n ] THEN result_n<br />
  ELSE result<br />
END<br />
</code></p>
<h3>Example</h3>
<p><code><br />
    SELECT m.paper_type    ,<br />
       m.paper_brand   ,<br />
       m.paper_grammage,<br />
       m.paper_width   ,<br />
       m.paper_length  ,<br />
       m.paper_stock_no,<br />
       (<br />
       CASE<br />
       WHEN NVL(smc.qty_reserved_onhand,0)  != NVL(st.sum_qty_r_oh,0) THEN 'QROH NOT TALLY'<br />
       WHEN NVL(smc.qty_reserved_incom,0)   != NVL(st.sum_qty_r_incom,0) THEN 'QRINC NOT TALLY'<br />
       WHEN NVL(smc.ton_reserved_onhand,0)  != NVL(st.sum_ton_r_oh,0) THEN 'TROH NOT TALLY'<br />
       WHEN NVL(smc.ton_reserved_incom,0)   != NVL(st.sum_ton_r_incom,0) THEN 'TRINC NOT TALLY'<br />
       END<br />
       ) ERROR_MESSAGE<br />
from  paper_stock_master m<br />
</code></p>
<p>
Personally, I use Syntax #2 most of the time. I don&#8217;t know why but maybe it just happened that I find it more suitable to use in the situations that I needed the CASE statement.
</p>
<h3>Difference Between DECODE and CASE WHEN</h3>
<p>The most fundamental difference between the two oracle statements is that in DECODE, you are comparing a field or value in a given set of values or fields. It&#8217;s actually a shorthand for IF..ELSIF..ELSE statement with the condition all set to equals (=). CASE WHEN is almost the same but you can use any conditional operator (i.e, =,!=, >, >= , <, <=, etc) thereby giving you more freedom and flexibility in writing your code.
</p>
</p>
<p>In may instances CASE WHEN helped me reduce the number of lines of my codes as well as optimize the performance. On top of that, I no longer need a full pl/sql program with multiple queries and even cursors to be able to provide the result that a simple CASE statement can provide. However CASE, like any other sql commands, is only applicable for certain scenarios. It&#8217;s not a magic keyword that will solve/apply to everything. So you have to weigh your options if you need it or not.
</p>
<p>Ciao!</p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/oracle-case-when-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Could not locate OCI dll Error</title>
		<link>http://kwatog.com/blog/oracle/could-not-locate-oci-dll-error/</link>
		<comments>http://kwatog.com/blog/oracle/could-not-locate-oci-dll-error/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 13:02:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[oci dll]]></category>
		<category><![CDATA[pl/sql developer]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=151</guid>
		<description><![CDATA[If you are using 10g client with PL/SQL developer, you may encounter the message &#8220;Initialization error: Could not locate OCI dll&#8221; when launching PL/SQL Developer. It does not happen with the 8i client so I already suspected that it must be with the 10g client that I recently installed. Luckily, I found this thread in [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using 10g client with PL/SQL developer, you may encounter the message &#8220;Initialization error: Could not locate OCI dll&#8221; when launching PL/SQL Developer. It does not happen with the 8i client so I already suspected that it must be with the 10g client that I recently installed. Luckily, I found this <a href="http://forums.oracle.com/forums/thread.jspa?threadID=620900">thread</a> in Oracle OTN forum and the solution seems to be easy.</p>
<p>All I have to do is copy a whole bunch of files from the ORAHOME folder to ORAHOME\bin. It seems like PL/SQL Developer is hardwired to find the files under the bin folder. It did the trick and my sql editor is now working. I hope it fixes yours too. </p>
<p>Here&#8217;s the screenshot of the files I copied. Take note that I copied them instead of just moving so as not to break anything. </p>
<p><a href="http://kwatog.com/blog/oracle/could-not-locate-oci-dll-error/attachment/oracle_files_copy_to_bin/" rel="attachment wp-att-171"><img src="http://kwatog.com/wp-content/uploads/2009/09/oracle_files_copy_to_bin-300x231.jpg" alt="oracle_files_copy_to_bin" title="oracle_files_copy_to_bin" width="300" height="231" class="alignnone size-medium wp-image-171" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/could-not-locate-oci-dll-error/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
