<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: ora_hash function</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Thu, 23 May 2013 12:47:17 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Surprises &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-49569</link>
		<dc:creator><![CDATA[Surprises &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Thu, 30 Aug 2012 17:55:44 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-49569</guid>
		<description><![CDATA[[...] more recently the topic of the sys_op_map_nonnull() function came up in some comments about the ora_hash function &#8211; and I made a passing comment about the function appearing in materialized view refreshes [...]]]></description>
		<content:encoded><![CDATA[<p>[...] more recently the topic of the sys_op_map_nonnull() function came up in some comments about the ora_hash function &#8211; and I made a passing comment about the function appearing in materialized view refreshes [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-47285</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 20 Jun 2012 11:04:52 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-47285</guid>
		<description><![CDATA[Padders,

Excellent - thanks for posting that information.]]></description>
		<content:encoded><![CDATA[<p>Padders,</p>
<p>Excellent &#8211; thanks for posting that information.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Padders</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-47284</link>
		<dc:creator><![CDATA[Padders]]></dc:creator>
		<pubDate>Wed, 20 Jun 2012 10:52:13 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-47284</guid>
		<description><![CDATA[I thought I&#039;d just add that converting NUMBER or DATE values to their internal representations with (for example) DBMS_STATS.PREPARE_COLUMN_VALUES and converting the result to VARCHAR2 with (for example) UTL_RAW.CAST_TO_VARCHAR2 appears to allow the demonstrated equivalence between ORA_HASH and DBMS_UTILITY.GET_HASH_VALUE to be extended to these data types.]]></description>
		<content:encoded><![CDATA[<p>I thought I&#8217;d just add that converting NUMBER or DATE values to their internal representations with (for example) DBMS_STATS.PREPARE_COLUMN_VALUES and converting the result to VARCHAR2 with (for example) UTL_RAW.CAST_TO_VARCHAR2 appears to allow the demonstrated equivalence between ORA_HASH and DBMS_UTILITY.GET_HASH_VALUE to be extended to these data types.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-35750</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 11 Mar 2010 12:17:56 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-35750</guid>
		<description><![CDATA[Flado,
That was a nice little investigation.

The answer to &quot;how does Oracle&quot; deal with this problem internally is simple - it doesn&#039;t.  

I found the function originally while sorting out some client problems with materialized view refresh - so I&#039;ve just re-created one of my test cases with a varchar2(4000) column - this is what happens when the refresh tries to run:

[sourcecode]
ERROR at line 1:
ORA-12008: error in materialized view refresh path
ORA-01706: user function result value was too large
[/sourcecode]

Thanks for the comment about the seminar - you should have said hello !  My bad luck seems to be over (at least nothing&#039;s gone wrong today, but that&#039;s because a client phoned up last night and postponed a meeting because they had to rebuild their database).]]></description>
		<content:encoded><![CDATA[<p>Flado,<br />
That was a nice little investigation.</p>
<p>The answer to &#8220;how does Oracle&#8221; deal with this problem internally is simple &#8211; it doesn&#8217;t.  </p>
<p>I found the function originally while sorting out some client problems with materialized view refresh &#8211; so I&#8217;ve just re-created one of my test cases with a varchar2(4000) column &#8211; this is what happens when the refresh tries to run:</p>
<pre class="brush: plain; title: ; notranslate">
ERROR at line 1:
ORA-12008: error in materialized view refresh path
ORA-01706: user function result value was too large
</pre>
<p>Thanks for the comment about the seminar &#8211; you should have said hello !  My bad luck seems to be over (at least nothing&#8217;s gone wrong today, but that&#8217;s because a client phoned up last night and postponed a meeting because they had to rebuild their database).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flado</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-35749</link>
		<dc:creator><![CDATA[Flado]]></dc:creator>
		<pubDate>Thu, 11 Mar 2010 10:42:29 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-35749</guid>
		<description><![CDATA[It appears that sys_op_map_nonnull() has its own limitations:
[sourcecode]

VERSION
-----------------
10.2.0.3.0
select &#039;fail&#039; from dual where sys_op_map_nonnull(rpad(&#039;x&#039;,4000))!=sys_op_map_nonnull(null)
                   *
ERROR at line 1:
ORA-01706: user function result value was too large
[/sourcecode]

It appears to work by appending a zero byte (0x00) to whatever the binary representation of its argument is, and by returning hextoraw(&#039;FF&#039;) in the case of a NULL argument:
[sourcecode]
SQL&gt;select sys_op_map_nonnull(&#039;&#039;) somn_null from dual;

SOMN_NULL
----------
FF
SQL&gt;select
  2     dump(&#039;A&#039;)      dump_a,  sys_op_map_nonnull(&#039;A&#039;)       somn_a,
  3     dump(chr(255)) dump_ff, sys_op_map_nonnull(chr(255))  somn_ff
  4  from dual;

DUMP_A           SOMN_A     DUMP_FF          SOMN_FF
---------------- ---------- ---------------- ----------
Typ=96 Len=1: 65 4100       Typ=1 Len=1: 255 FF00
SQL&gt;set echo off
[/sourcecode]
I&#039;ve checked this behaviour on values of several types (number, date, varchar2, interval day to second, and a user-defined type).
Of course, sys_op_map_nonnull() needs to append that zero byte to avoid matching a NULL value to the non-NULL value chr(255). Unfortunately, this renders it unusable for columns of type varchar2(4000). It would be interesting to see how Oracle deals with this problem internally :-)

@Jonathan: BTW, I liked your seminar on indexing this week. Hope you got rid of that streak of bad luck :-)

Cheers!

Flado]]></description>
		<content:encoded><![CDATA[<p>It appears that sys_op_map_nonnull() has its own limitations:</p>
<pre class="brush: plain; title: ; notranslate">

VERSION
-----------------
10.2.0.3.0
select 'fail' from dual where sys_op_map_nonnull(rpad('x',4000))!=sys_op_map_nonnull(null)
                   *
ERROR at line 1:
ORA-01706: user function result value was too large
</pre>
<p>It appears to work by appending a zero byte (0&#215;00) to whatever the binary representation of its argument is, and by returning hextoraw(&#8216;FF&#8217;) in the case of a NULL argument:</p>
<pre class="brush: plain; title: ; notranslate">
SQL&gt;select sys_op_map_nonnull('') somn_null from dual;

SOMN_NULL
----------
FF
SQL&gt;select
  2     dump('A')      dump_a,  sys_op_map_nonnull('A')       somn_a,
  3     dump(chr(255)) dump_ff, sys_op_map_nonnull(chr(255))  somn_ff
  4  from dual;

DUMP_A           SOMN_A     DUMP_FF          SOMN_FF
---------------- ---------- ---------------- ----------
Typ=96 Len=1: 65 4100       Typ=1 Len=1: 255 FF00
SQL&gt;set echo off
</pre>
<p>I&#8217;ve checked this behaviour on values of several types (number, date, varchar2, interval day to second, and a user-defined type).<br />
Of course, sys_op_map_nonnull() needs to append that zero byte to avoid matching a NULL value to the non-NULL value chr(255). Unfortunately, this renders it unusable for columns of type varchar2(4000). It would be interesting to see how Oracle deals with this problem internally :-)</p>
<p>@Jonathan: BTW, I liked your seminar on indexing this week. Hope you got rid of that streak of bad luck :-)</p>
<p>Cheers!</p>
<p>Flado</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-35741</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Wed, 10 Mar 2010 22:17:41 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-35741</guid>
		<description><![CDATA[Dharmendra,
If you want to use &lt;em&gt;&lt;strong&gt;nvl()&lt;/strong&gt;&lt;/em&gt; in this case, what value are you going to use when the column is null ?
Will you (and everyone who every uses an Oracle database) always be able to find a value that isn&#039;t also a legal value for the column ?

&lt;em&gt;&lt;strong&gt;sys_op_map_nonnull()&lt;/strong&gt;&lt;/em&gt; is designed to return a value that cannot legally appear in the column, so you can&#039;t compare a null with a real column value and get a match by accident.]]></description>
		<content:encoded><![CDATA[<p>Dharmendra,<br />
If you want to use <em><strong>nvl()</strong></em> in this case, what value are you going to use when the column is null ?<br />
Will you (and everyone who every uses an Oracle database) always be able to find a value that isn&#8217;t also a legal value for the column ?</p>
<p><em><strong>sys_op_map_nonnull()</strong></em> is designed to return a value that cannot legally appear in the column, so you can&#8217;t compare a null with a real column value and get a match by accident.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dharmendra</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-35730</link>
		<dc:creator><![CDATA[Dharmendra]]></dc:creator>
		<pubDate>Tue, 09 Mar 2010 21:32:55 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-35730</guid>
		<description><![CDATA[Thanks Flado &amp; Jonathan for you answers..

Regarding sys_op_map_nonnull(old.col1) != sys_op_map_nonnull(new.col1), can&#039;t I use simple NVL function instead?]]></description>
		<content:encoded><![CDATA[<p>Thanks Flado &amp; Jonathan for you answers..</p>
<p>Regarding sys_op_map_nonnull(old.col1) != sys_op_map_nonnull(new.col1), can&#8217;t I use simple NVL function instead?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flado</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-35645</link>
		<dc:creator><![CDATA[Flado]]></dc:creator>
		<pubDate>Sun, 28 Feb 2010 15:57:14 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-35645</guid>
		<description><![CDATA[Jonathan,
No magic, it appears. I ran some quick tests in SQL Workshop on apex.oracle.com and found that
[sourcecode]
where sys_op_map_nonnull(c1)=sys_op_map_nonnull(&#039;42&#039;)
[/sourcecode]
will only use a function-based index on sys_op_map_nonnull(c1) and not a normal one. The result type appears to be RAW (based on HEXTORAW() and RAWTOHEX() calls in the plan predicates)

Cheers!
Flado]]></description>
		<content:encoded><![CDATA[<p>Jonathan,<br />
No magic, it appears. I ran some quick tests in SQL Workshop on apex.oracle.com and found that</p>
<pre class="brush: plain; title: ; notranslate">
where sys_op_map_nonnull(c1)=sys_op_map_nonnull('42')
</pre>
<p>will only use a function-based index on sys_op_map_nonnull(c1) and not a normal one. The result type appears to be RAW (based on HEXTORAW() and RAWTOHEX() calls in the plan predicates)</p>
<p>Cheers!<br />
Flado</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-35640</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sun, 28 Feb 2010 14:53:38 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-35640</guid>
		<description><![CDATA[Flado,

I can&#039;t answer your last question - I&#039;ve not yet come across a system where I needed to test the effects of mixing &lt;em&gt;&lt;strong&gt;sys_op_map_nonnull()&lt;/strong&gt;&lt;/em&gt; and indexes.

I appreciate succinctness by the way - one of the hardest things about writing is the difficulty of drawing the line between so short you miss the detail and so long that the point gets lost in the detail. I think your comment got the right amount of detail in the right amount of text.
]]></description>
		<content:encoded><![CDATA[<p>Flado,</p>
<p>I can&#8217;t answer your last question &#8211; I&#8217;ve not yet come across a system where I needed to test the effects of mixing <em><strong>sys_op_map_nonnull()</strong></em> and indexes.</p>
<p>I appreciate succinctness by the way &#8211; one of the hardest things about writing is the difficulty of drawing the line between so short you miss the detail and so long that the point gets lost in the detail. I think your comment got the right amount of detail in the right amount of text.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flado</title>
		<link>http://jonathanlewis.wordpress.com/2009/11/21/ora_hash-function/#comment-35638</link>
		<dc:creator><![CDATA[Flado]]></dc:creator>
		<pubDate>Sun, 28 Feb 2010 14:42:09 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=202#comment-35638</guid>
		<description><![CDATA[Thanks, Jonathan. I tried to keep the post as succinct as possible, that&#039;s why I only mentioned the problem with NULLs in passing. 
Thanks for pointer to sys_op_map_nonnull() - is it a magic function that could still use an index on old.col1?

Cheers,
Flado]]></description>
		<content:encoded><![CDATA[<p>Thanks, Jonathan. I tried to keep the post as succinct as possible, that&#8217;s why I only mentioned the problem with NULLs in passing.<br />
Thanks for pointer to sys_op_map_nonnull() &#8211; is it a magic function that could still use an index on old.col1?</p>
<p>Cheers,<br />
Flado</p>
]]></content:encoded>
	</item>
</channel>
</rss>
