<?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>jhunterj.com &#187; decode</title>
	<atom:link href="http://jhunterj.com/tag/decode/feed/" rel="self" type="application/rss+xml" />
	<link>http://jhunterj.com</link>
	<description>J. Hunter Johnson—I&#039;m just this geek you (should) know.</description>
	<lastBuildDate>Sat, 14 Mar 2015 12:10:39 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>Decoding SQL&#8217;s Decode</title>
		<link>http://jhunterj.com/2013/02/05/decoding-sqls-decode/</link>
		<comments>http://jhunterj.com/2013/02/05/decoding-sqls-decode/#comments</comments>
		<pubDate>Tue, 05 Feb 2013 12:32:29 +0000</pubDate>
		<dc:creator><![CDATA[Hunter]]></dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[decode]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://jhunterj.com/?p=205</guid>
		<description><![CDATA[I came across a SQL function I was not familiar with: decode. I looked it up and immediately replaced it with a CASE statement (in addition to other code cleanup). I&#8217;m afraid I don&#8217;t understand the existence of Oracle SQL&#8217;s <a class="more-link" href="http://jhunterj.com/2013/02/05/decoding-sqls-decode/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I came across a SQL function I was not familiar with: decode. I looked it up and immediately replaced it with a CASE statement (in addition to other code cleanup). I&#8217;m afraid I don&#8217;t understand the existence of Oracle SQL&#8217;s decode() function:</p>
<pre>decode(expression,
       search, result
       [, search , result]...
       [, default]
      )</pre>
<p>seems functionally equivalent to</p>
<pre>CASE expression 
   WHEN search THEN result
   [WHEN search THEN result]...
   [ELSE default]
END</pre>
<p><div style="width: 260px" class="wp-caption alignright"><a href="http://commons.wikimedia.org/wiki/File:Gorilla_Scratching_Head.jpg"><img alt="Gorilla Scratching Head" src="http://upload.wikimedia.org/wikipedia/commons/0/08/Gorilla_Scratching_Head.jpg" width="250" /></a><p class="wp-caption-text">By Steven Straiton (originally posted to Flickr as Gorilla) [<a href="http://creativecommons.org/licenses/by/2.0">CC-BY-2.0</a>], via Wikimedia Commons</p></div>except the CASE version</p>
<ul>
<li>has no limitation of &#8220;only&#8221; 255 total expression + search + result + default parameters</li>
<li>is easier to read</li>
<li>works in PL/SQL context</li>
<li>is ANSI-compliant</li>
</ul>
<p>The only &#8220;benefit&#8221; to decode I could find is that the decode function will attempt to convert all of the results to the type of the first result, while CASE just errors if you mix types. To me, that benefit would simply encourage sloppy coding and keep you from noticing buggy code as quickly.</p>
<p>So, what&#8217;s the point? Are their coders out there who &#8220;get&#8221; the function syntax more readily than the CASE syntax, so it helps their coding efficiency? Or is there a benefit I&#8217;m missing?</p>
<p style="text-align: right;">—jhunterj</p>
]]></content:encoded>
			<wfw:commentRss>http://jhunterj.com/2013/02/05/decoding-sqls-decode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
