<?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 &#38; co.&#187; Oracle</title>
	<atom:link href="http://kwatog.com/tag/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://kwatog.com</link>
	<description>tech notes and general nonsense</description>
	<lastBuildDate>Tue, 31 Jan 2012 06:27:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>UTF_FILE and Directories</title>
		<link>http://kwatog.com/blog/oracle/utf_file-and-directories/</link>
		<comments>http://kwatog.com/blog/oracle/utf_file-and-directories/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 00:38:33 +0000</pubDate>
		<dc:creator>kwatog</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[all_directories]]></category>
		<category><![CDATA[directories]]></category>
		<category><![CDATA[folders]]></category>
		<category><![CDATA[utf_file]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=43</guid>
		<description><![CDATA[In case you are maintaining a pl/sql program developed by someone else and that program writes into a file, then basically that file is written to a folder/directory. And since the directories are saved in codes, you have to find the meaning (or location) of those codes. The code below will help you display the [...]]]></description>
			<content:encoded><![CDATA[<p>In case you are maintaining a pl/sql program developed by someone else and that program writes into a file, then basically that file is written to a folder/directory. And since the directories are saved in codes, you have to find the meaning (or location) of those codes. The code below will help you display the information required.</p>
<p><code>SELECT * FROM ALL_DIRECTORIES;</code></p>
<p>The query above will display all the directories accessible to the current user. They are folders in the server where you can write your output files. For some reason, I forgot about this twice already and had to scour the web to find it. The problem is, I also forgot the keywords. So, I&#8217;m writing it now.</p>
<p>To register new directories, you can follow the example below.</p>
<p>Example<br />
<code>create or replace directory mydir as 'c:\mydirectory';</code></p>
<p>To use, run the code below.</p>
<p><code>declare<br />
f utl_file.file_type;<br />
begin<br />
f := utl_file.fopen('MYDIR', 'myfilename.txt', 'w');<br />
utl_file.put_line(f, 'just another line text 1');<br />
utl_file.put_line(f, 'just another line text 2');<br />
utl_file.fclose(f);<br />
end;</code></p>
<h4>Incoming search terms:</h4><ul><li>utf_file</li><li>utl_file all_directories</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/utf_file-and-directories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Power Function</title>
		<link>http://kwatog.com/blog/oracle/oracle-power-function/</link>
		<comments>http://kwatog.com/blog/oracle/oracle-power-function/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 03:30:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[power function]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=681</guid>
		<description><![CDATA[There are some pl/sql functions that you rarely use and we always forget the syntax.And here&#8217;s another example &#8212; the power function. You know, that&#8217;s the n to the power of x (n^x). Again, I feel a bit ashamed for forgetting this one. Here&#8217;s the syntax. power(m,n); whereby m is the base. n is the [...]]]></description>
			<content:encoded><![CDATA[<p>There are some pl/sql functions that you rarely use and we always forget the syntax.And here&#8217;s another example &#8212; the power function.  You know, that&#8217;s the n to the power of x (n^x). Again, I feel a bit ashamed for forgetting this one. Here&#8217;s the syntax.<br />
<span id="more-681"></span><br />
<code><br />
power(m,n);<br />
</code></p>
<p>whereby<br />
m is the base.<br />
n is the exponent.</p>
<p>Example<br />
<code><br />
power(36,5);<br />
</code><br />
will return 1679616</p>
<p>Take note that this function returns NUMBER as the data type. That means the maximum value can only be 1.0 x 10^126. Later versions (10g onwards) can use binary_double as the base which makes the function output binary_double. I don&#8217;t know where you would need that large number, though. Also, if m is negative, then n must be an integer.</p>
<p>In case you are asking where I need it, there&#8217;s this code conversion whereby I needed to use the power function to get the value of a particular character. The exponent(n) is not fixed so I needed this function. To be specific, the function involves the pl/sql version of RowIdToRowIdNum of Siebel. I&#8217;ll post the code later.</p>
<p>References:</p>
<p>http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1594387900346571874</p>
<h4>Incoming search terms:</h4><ul><li>oracle power</li><li>oracle power function</li><li>oracle power function negative</li><li>oracle power functions</li><li>oracle sql display power</li><li>power function in sql oracle</li><li>power function pl/sql integers</li><li>power oracle binary_double ask tom</li><li>powerc oracle</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/oracle-power-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle MERGE command</title>
		<link>http://kwatog.com/blog/oracle/oracle-merge-command/</link>
		<comments>http://kwatog.com/blog/oracle/oracle-merge-command/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 02:57:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[DML]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[merge]]></category>
		<category><![CDATA[statement]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[upsert]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=468</guid>
		<description><![CDATA[Oracle MERGE command was added in 9i but I only learned about it lately. This command is sometimes referred to as UPSERT because in one statement, you can both update and insert records into a target. Based on the matching condition, MERGE can update existing records if a match is found or insert new record [...]]]></description>
			<content:encoded><![CDATA[<p>Oracle MERGE command was added in 9i but I only learned about it lately. This command is sometimes referred to as UPSERT because in one statement, you can both update and insert records into a target. Based on the matching condition, MERGE can update existing records if a match is found or insert new record if not. Prior to 9i, we need separate sql statements or a PL/SQL program to do this.</p>
<p><span id="more-468"></span><br />
<code><br />
MERGE INTO tstg_idl_approach a<br />
USING tmdb_idl_approach b<br />
ON (a.approach_id = b.approach_id)<br />
WHEN MATCHED THEN<br />
   UPDATE SET   a.approach_code = b.approach_code ,<br />
                a.current_ind   = b.current_ind<br />
WHEN NOT MATCHED THEN<br />
	INSERT (approach_id  ,<br />
		    approach_code,<br />
            current_ind  )<br />
	VALUES (b.approach_id  ,<br />
            b.approach_code,<br />
            b.current_ind   );<br />
</code><br />
For further reading, I recommend visiting <a href="http://www.oracle-developer.net/display.php?id=203">http://www.oracle-developer.net/display.php?id=203</a>.</p>
<h4>Incoming search terms:</h4><ul><li>oracle merge statement</li><li>merge oracle</li><li>oracle merge</li><li>oracle merge statement in loop</li><li>oracle merge statement tech on the web</li><li>oracle merge statement when not matched then print message</li><li>oracle merge tech on the net</li><li>oracle merge when matched then insert</li><li>oracle user if in merge statement</li><li>pl/sql merge log</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/oracle-merge-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Rows to One Column</title>
		<link>http://kwatog.com/blog/oracle/convert-rows-to-one-column/</link>
		<comments>http://kwatog.com/blog/oracle/convert-rows-to-one-column/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 10:23:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[convert row to col]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=262</guid>
		<description><![CDATA[Converting rows to column is a breeze if you are using Microsoft Access or reporting tools like Oracle Reports Builder. However, there are times that you&#8217;ll also need it for something else. I mean like displaying rows to one column in a SQL*Plus report. So how leh? (imagine that saying with a Singaporean accent) Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Converting rows to column is a breeze if you are using <strong>Microsoft Access </strong>or reporting tools like <strong>Oracle Reports Builder</strong>. However, there are times that you&#8217;ll also need it for something else. I mean like displaying rows to one column in a <strong>SQL*Plus</strong> report. So how leh? (<em>imagine that saying with a Singaporean accent</em>)<br />
<span id="more-262"></span><br />
Here&#8217;s one.</p>
<h5>XMLAGG (Available since Oracle 9i)</h5>
<p><code><br />
select rtrim (xmlagg (xmlelement (e, email_add || ',')).extract ('//text()'), ',') email_add<br />
from email_groups<br />
where email_group = '1-A945-9';<br />
</code><br />
In that example, I needed to display all the email addresses in an email group. The output should be separated by comma so that I can pass it onto the email client without any problem nor any additional codes.</p>
<p>There&#8217;s more at <a href="http://www.dba-oracle.com/t_converting_rows_columns.htm">Burleson Consulting</a> in case you want other techniques. </p>
<h4>Incoming search terms:</h4><ul><li>convert rows to columns in oracle</li><li>convert row to column in oracle</li><li>oracle rows to columns</li><li>oracle rows to one column</li><li>oracle select rows to column</li><li>oracle xmlagg</li><li>oracle xmlagg row to col</li><li>report builder convert rows to columns</li><li>row to col oracle</li><li>row to column in oracle</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/convert-rows-to-one-column/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date Functions in MySQL</title>
		<link>http://kwatog.com/blog/date-function-in-mysql/</link>
		<comments>http://kwatog.com/blog/date-function-in-mysql/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 01:23:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[add_months]]></category>
		<category><![CDATA[date_add]]></category>
		<category><![CDATA[months_between]]></category>
		<category><![CDATA[Oracle]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=382</guid>
		<description><![CDATA[Here&#8217;s few of the usual equivalent Oracle data functions in MySQL. DATE ADD (SYSDATE +/-1) SELECT DATE_ADD(SYSDATE(),INTERVAL 1 DAY); SELECT DATE_ADD(SYSDATE(),INTERVAL -10 DAY); ADD_MONTHS SELECT DATE_ADD(SYSDATE(),INTERVAL 1 MONTH); TRUNC() SELECT DATE(SYSDATE()); TO_DATE() SELECT STR_TO_DATE( '07-08-2010', '%d-%m-%Y' ); TIME DIFFERENCE SELECT TIMESTAMPDIFF( SECOND , '2010-01-07 23:50:59', SYSDATE( ) ) /3600 /24 day, TIMESTAMPDIFF( SECOND , '2010-01-07 [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s few of the usual equivalent Oracle data functions in MySQL.</p>
<p><strong>DATE ADD (SYSDATE +/-1)</strong><br />
<code><br />
SELECT DATE_ADD(SYSDATE(),INTERVAL 1 DAY);<br />
SELECT DATE_ADD(SYSDATE(),INTERVAL -10 DAY);<br />
</code><br />
<span id="more-382"></span><br />
<strong>ADD_MONTHS</strong><br />
<code><br />
SELECT DATE_ADD(SYSDATE(),INTERVAL 1 MONTH);<br />
</code></p>
<p><strong>TRUNC()</strong><br />
<code><br />
SELECT DATE(SYSDATE());<br />
</code></p>
<p><strong>TO_DATE()</strong><br />
<code><br />
SELECT STR_TO_DATE( '07-08-2010', '%d-%m-%Y' );</code></p>
<p><strong>TIME DIFFERENCE</strong><br />
<code><br />
SELECT TIMESTAMPDIFF(<br />
SECOND , '2010-01-07 23:50:59', SYSDATE( ) ) /3600 /24 day,<br />
TIMESTAMPDIFF(<br />
SECOND , '2010-01-07 23:50:59', SYSDATE( ) )  /3600 hours,<br />
TIMESTAMPDIFF(<br />
SECOND , '2010-01-07 23:50:59', SYSDATE( ) )  /60 mins,<br />
TIMESTAMPDIFF(<br />
SECOND , '2010-01-07 23:50:59', SYSDATE( ) )  secs,<br />
</code><br />
In the preceding example, I could have just used HOUR, MINUTE, DAY, MONTH or YEAR interval but in real world, I mostly use SECOND for a more accurate results. That&#8217;s not to say timestampdiff is not accurate. Maybe because I&#8217;m used in how I do it in Oracle. </p>
<p><strong>MONTHS_BETWEEN</strong><br />
<code><br />
SELECT TIMESTAMPDIFF(<br />
MONTH , '2010-01-07', SYSDATE( ) )  no_months<br />
</code></p>
<table>
<tr>
<td><strong>Specifier</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td><code>%a</code></td>
<td>Abbreviated weekday name                   (<code>Sun</code>..<code>Sat</code>)</td>
</tr>
<tr>
<td><code>%b</code></td>
<td>Abbreviated month name (<code>Jan</code>..<code>Dec</code>)</td>
</tr>
<tr>
<td><code>%c</code></td>
<td>Month, numeric (<code>0</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%D</code></td>
<td>Day of the month with English suffix (<code>0th</code>,                   <code>1st</code>, <code>2nd</code>,                   <code>3rd</code>, …)</td>
</tr>
<tr>
<td><code>%d</code></td>
<td>Day of the month, numeric (<code>00</code>..<code>31</code>)</td>
</tr>
<tr>
<td><code>%e</code></td>
<td>Day of the month, numeric (<code>0</code>..<code>31</code>)</td>
</tr>
<tr>
<td><code>%f</code></td>
<td>Microseconds (<code>000000</code>..<code>999999</code>)</td>
</tr>
<tr>
<td><code>%H</code></td>
<td>Hour (<code>00</code>..<code>23</code>)</td>
</tr>
<tr>
<td><code>%h</code></td>
<td>Hour (<code>01</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%I</code></td>
<td>Hour (<code>01</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%i</code></td>
<td>Minutes, numeric (<code>00</code>..<code>59</code>)</td>
</tr>
<tr>
<td><code>%j</code></td>
<td>Day of year (<code>001</code>..<code>366</code>)</td>
</tr>
<tr>
<td><code>%k</code></td>
<td>Hour (<code>0</code>..<code>23</code>)</td>
</tr>
<tr>
<td><code>%l</code></td>
<td>Hour (<code>1</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%M</code></td>
<td>Month name (<code>January</code>..<code>December</code>)</td>
</tr>
<tr>
<td><code>%m</code></td>
<td>Month, numeric (<code>00</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%p</code></td>
<td><code>AM</code> or <code>PM</code></td>
</tr>
<tr>
<td><code>%r</code></td>
<td>Time, 12-hour (<code>hh:mm:ss</code> followed by                   <code>AM</code> or <code>PM</code>)</td>
</tr>
<tr>
<td><code>%S</code></td>
<td>Seconds (<code>00</code>..<code>59</code>)</td>
</tr>
<tr>
<td><code>%s</code></td>
<td>Seconds (<code>00</code>..<code>59</code>)</td>
</tr>
<tr>
<td><code>%T</code></td>
<td>Time, 24-hour (<code>hh:mm:ss</code>)</td>
</tr>
<tr>
<td><code>%U</code></td>
<td>Week (<code>00</code>..<code>53</code>), where Sunday is the                   first day of the week</td>
</tr>
<tr>
<td><code>%u</code></td>
<td>Week (<code>00</code>..<code>53</code>), where Monday is the                   first day of the week</td>
</tr>
<tr>
<td><code>%V</code></td>
<td>Week (<code>01</code>..<code>53</code>), where Sunday is the                   first day of the week; used with <code>%X</code></td>
</tr>
<tr>
<td><code>%v</code></td>
<td>Week (<code>01</code>..<code>53</code>), where Monday is the                   first day of the week; used with <code>%x</code></td>
</tr>
<tr>
<td><code>%W</code></td>
<td>Weekday name (<code>Sunday</code>..<code>Saturday</code>)</td>
</tr>
<tr>
<td><code>%w</code></td>
<td>Day of the week                   (<code>0</code>=Sunday..<code>6</code>=Saturday)</td>
</tr>
<tr>
<td><code>%X</code></td>
<td>Year for the week where Sunday is the first day of the week, numeric,                   four digits; used with <code>%V</code></td>
</tr>
<tr>
<td><code>%x</code></td>
<td>Year for the week, where Monday is the first day of the week, numeric,                   four digits; used with <code>%v</code></td>
</tr>
<tr>
<td><code>%Y</code></td>
<td>Year, numeric, four digits</td>
</tr>
<tr>
<td><code>%y</code></td>
<td>Year, numeric (two digits)</td>
</tr>
<tr>
<td><code>%%</code></td>
<td>A literal “<code>%</code>” character</td>
</tr>
<tr>
<td><code>%<em><code>x</code></em></code></td>
<td><em><code>x</code></em>, for any                   “<em><code>x</code></em>” not listed                   above</td>
</tr>
</table>
<p>Reference:</p>
<p>http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html</p>
<h4>Incoming search terms:</h4><ul><li>mysql sysdate</li><li>add_months in mysql</li><li>mysql months_between</li><li>mysql trunc date</li><li>mysql add_months</li><li>add_months mysql</li><li>sysdate in mysql</li><li>mysql trunc date function</li><li>trunc function in mysql;</li><li>mysql truncate date to month</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/date-function-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle NVL Equivalent in MySQL</title>
		<link>http://kwatog.com/blog/mysql/oracle-nvl-equivalent-in-mysql/</link>
		<comments>http://kwatog.com/blog/mysql/oracle-nvl-equivalent-in-mysql/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 01:59:44 +0000</pubDate>
		<dc:creator>kwatog</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[isnull]]></category>
		<category><![CDATA[nvl]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[sybase]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=204</guid>
		<description><![CDATA[Here&#8217;s the MySQL equivalent of Oracle&#8217;s NVL and MSSQL/Sybase&#8217;s ISNULL functions. Syntax IFNULL(expr1,expr2) Usage If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. Take note that IFNULL() returns a numeric or string value, depending on the context in which it is used. I haven&#8217;t used it for other data types yet but [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the MySQL equivalent of Oracle&#8217;s NVL and MSSQL/Sybase&#8217;s ISNULL functions.</p>
<h3>Syntax</h3>
<p><code><br />
IFNULL(expr1,expr2)<br />
</code></p>
<h3>Usage</h3>
<p>If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. Take note that IFNULL() returns a numeric or string value, depending on the context in which it is used. I haven&#8217;t used it for other data types yet but I reckon it would have the same results. That is to return the same data type as that of expr1. Another important thing to remember is that expr1 and expr2 should have the same data type</p>
<h4>Incoming search terms:</h4><ul><li>nvl mysql</li><li>mysql nvl equivalent</li><li>nvl in mysql</li><li>mysql nvl</li><li>oracle nvl mysql</li><li>nvl equivalent in mysql</li><li>mysql nvl equivalent function</li><li>mysql аналог nvl</li><li>oracle nvl</li><li>NVL Oracle</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/mysql/oracle-nvl-equivalent-in-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL SEQUENCE Equivalent</title>
		<link>http://kwatog.com/blog/mysql/mysql-sequence-equivalent/</link>
		<comments>http://kwatog.com/blog/mysql/mysql-sequence-equivalent/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 03:37:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[nextval]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[sequence]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=197</guid>
		<description><![CDATA[Most Oracle guys (and I heard PostgreSQL, too) will be missing sequence in MySQL. The nearest equivalent that MySQL has for this feature is the AUTO INCREMENT field. However, auto increment is sometimes not sufficient and time will come that you will be missing it. Case in point is the alpha-numeric auto-generated code. In Oracle, [...]]]></description>
			<content:encoded><![CDATA[<p>Most Oracle guys (and I heard PostgreSQL, too) will be missing sequence in MySQL. The nearest equivalent that MySQL has for this feature is the AUTO INCREMENT field. However, auto increment is sometimes not sufficient and time will come that you will be missing it. </p>
<p>Case in point is the alpha-numeric auto-generated code. In Oracle, it&#8217;s easy to generate AA123, AA124, AA125, etc., etc. All we have to do is concat the alpha part (AA) and with the nextval of sequence. For MySQL, the alpha part and the numeric part have to be saved in separate fields.</p>
<p>However, Maresa of Microshell has created an alternative solution for it. The article discusses a way to emulate the nextval function in mysql.  It a nutshell, they created a table similar to the all_sequences of Oracle. This is where you insert your sequences. Then, create a function named nextval() function which increments and returns value of the sequence.<br />
You can check the procedure <a href="http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/1942">here</a>.</p>
<p>It&#8217;s pretty neat, actually. It&#8217;s an excellent alternative and you can even create similar functions like currval(), prevval(), among others. However, I have some reservations on his approach especially on the issue of concurrency. You see in Oracle, calling the nextval() will increment the value and that&#8217;s already persisted (saved) in the sequence table even without saving your query/dml statement. On this approach, other queries accessing the pseudo-nextval will have to wait until your query finishes. Not a good idea. </p>
<p>So for now, I&#8217;ll will still have to make do with whatever MySQL is providing. If there&#8217;s any consolation, MySQL provides LAST_INSERT_ID()  function in case you want to get the latest id inserted. See details here <a href="http://dev.mysql.com/doc/refman/5.0/en/information-functions.html">here</a>. </p>
<p>So I&#8217;m just hoping that MySQL will implement an equivalent feature in the near future. With the imminent takeover by Oracle, I&#8217;m actually hoping that development of MySQL will push through and take a steam. We all know that the development of this widely used open-source database engine has been hampered ever since Sun bought it. </p>
<p>Sequence is a little feature. But little as it seems, it solves a lot of problems and helps improve code development time.</p>
<h4>Incoming search terms:</h4><ul><li>mysql sequence nextval</li><li>mysql nextval</li><li>nextval in mysql</li><li>postgresql sequence equivalent in mysql</li><li>oracle sequence in mysql</li><li>oracle sequence equivalent in mysql</li><li>sequence alternative in mysql</li><li>mysql sequentions</li><li>mysql sequence procedure</li><li>emulating nextval function to get sequence in mysql</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/mysql/mysql-sequence-equivalent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle WITH Clause  (Subquery Refactoring)</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>
<h4>Incoming search terms:</h4><ul><li>oracle with clause</li><li>with clause in oracle</li><li>oracle with clause syntax</li><li>oracle sql subquery refactor</li><li>subquery refactoring oracle</li><li>subquery optimization pl-sql</li><li>how to create the subquery in oracle using with clause</li><li>subquery factoring clause + procedure</li><li>random pl sql de un subquery</li><li>subquery sp oracle</li></ul>]]></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>
<h4>Incoming search terms:</h4><ul><li>oracle case when</li><li>oracle case sta</li><li>sql optimize case statement</li><li>performance select case statement in oracle</li><li>oracle case when syntax</li><li>oracle case when statement</li><li>oracle case when as</li><li>case statement in oracle</li><li>oracle case decode optimization</li><li>optimize the case statement in orac;e</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/oracle-case-when-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rename Table in Oracle</title>
		<link>http://kwatog.com/blog/oracle/rename-table-in-oracle/</link>
		<comments>http://kwatog.com/blog/oracle/rename-table-in-oracle/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 10:35:05 +0000</pubDate>
		<dc:creator>kwatog</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[rename table]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=137</guid>
		<description><![CDATA[SYNTAX alter table table_name rename to new_table_name; Example alter table employee rename to employee_bak; Incoming search terms:rename oracle table]]></description>
			<content:encoded><![CDATA[<p>SYNTAX<br />
<code><br />
alter table<br />
   table_name<br />
rename to<br />
   new_table_name;<br />
</code></p>
<p>Example<br />
<code><br />
alter table<br />
   employee<br />
rename to<br />
   employee_bak;<br />
</code></p>
<h4>Incoming search terms:</h4><ul><li>rename oracle table</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/oracle/rename-table-in-oracle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!--
Hyper cache file: 29c7cc0e06b292040e7f8f95dd3b158c
Cache created: 05-02-2012 01:36:44
HCE Version: 0.9.8
Load AVG: 0.04(5)
-->
