<?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: Overflow</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2011/05/13/overflow/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Wed, 19 Jun 2013 18:51:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Sokrates</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40532</link>
		<dc:creator><![CDATA[Sokrates]]></dc:creator>
		<pubDate>Tue, 17 May 2011 14:05:49 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40532</guid>
		<description><![CDATA[yeah, thanks, it&#039;s clear now]]></description>
		<content:encoded><![CDATA[<p>yeah, thanks, it&#8217;s clear now</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40531</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Tue, 17 May 2011 13:20:47 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40531</guid>
		<description><![CDATA[I should have included a comment that it might be expected by the developers, but it would be most unexpected to anyone whose code had been working for the last 10 years. It&#039;s the sort of thing that merits a &quot;notable change in behaviour&quot; bulletin; mind you, if there was one I probably wouldn&#039;t have noticed it.]]></description>
		<content:encoded><![CDATA[<p>I should have included a comment that it might be expected by the developers, but it would be most unexpected to anyone whose code had been working for the last 10 years. It&#8217;s the sort of thing that merits a &#8220;notable change in behaviour&#8221; bulletin; mind you, if there was one I probably wouldn&#8217;t have noticed it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40530</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Tue, 17 May 2011 13:18:38 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40530</guid>
		<description><![CDATA[I think the problem here is the use of the work &quot;integer&quot; in &quot;integer arithmetic&quot;. It doesn&#039;t relate to integers in pl/sql, which uses the term as a shorthand for number(*,0) or something similar. The type that does &quot;integer arithmetic&quot; is the pls_integer:

[sourcecode]

  1  declare
  2     v number(38);
  3     j pls_integer;
  4  begin
  5     j := 256;
  6     v := j * j * j * j;
  7* end;
SQL&gt; /
declare
*
ERROR at line 1:
ORA-01426: numeric overflow
ORA-06512: at line 6
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>I think the problem here is the use of the work &#8220;integer&#8221; in &#8220;integer arithmetic&#8221;. It doesn&#8217;t relate to integers in pl/sql, which uses the term as a shorthand for number(*,0) or something similar. The type that does &#8220;integer arithmetic&#8221; is the pls_integer:</p>
<pre class="brush: plain; title: ; notranslate">

  1  declare
  2     v number(38);
  3     j pls_integer;
  4  begin
  5     j := 256;
  6     v := j * j * j * j;
  7* end;
SQL&gt; /
declare
*
ERROR at line 1:
ORA-01426: numeric overflow
ORA-06512: at line 6
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bradd Piontek</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40529</link>
		<dc:creator><![CDATA[Bradd Piontek]]></dc:creator>
		<pubDate>Mon, 16 May 2011 19:59:01 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40529</guid>
		<description><![CDATA[I think this only applies if all the values are literals. By introducing a function, you are causing the PL/SQL engine to use the floating-point arithmetic engine. 
  1  declare
  2   v1 number;
  3   v2 integer := 256;
  4  begin
  5   v1 := cast(256 as varchar2)*256*256*256;
  6  -- v1 := 256*256*256*256;
  7   dbms_output.put_line(v1);
  8* end;
SQL&gt; /
4294967296

PL/SQL procedure successfully completed.

Sorry, it has been almost 2.5 years since I first blogged on this upgrade issue. I&#039;ve only seen it happen when using literals.]]></description>
		<content:encoded><![CDATA[<p>I think this only applies if all the values are literals. By introducing a function, you are causing the PL/SQL engine to use the floating-point arithmetic engine.<br />
  1  declare<br />
  2   v1 number;<br />
  3   v2 integer := 256;<br />
  4  begin<br />
  5   v1 := cast(256 as varchar2)*256*256*256;<br />
  6  &#8212; v1 := 256*256*256*256;<br />
  7   dbms_output.put_line(v1);<br />
  8* end;<br />
SQL&gt; /<br />
4294967296</p>
<p>PL/SQL procedure successfully completed.</p>
<p>Sorry, it has been almost 2.5 years since I first blogged on this upgrade issue. I&#8217;ve only seen it happen when using literals.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flavio Casetta</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40528</link>
		<dc:creator><![CDATA[Flavio Casetta]]></dc:creator>
		<pubDate>Mon, 16 May 2011 09:43:16 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40528</guid>
		<description><![CDATA[Even if it&#039;s expected behaviour, it looks horrible to me.
What about the &quot;backward compatibility&quot; concept?
And above all, is there any *real* advantage?
I think that extreme optimization should be knowingly applied by the programmer using an integer variable as destination.
By the same logic, we should not be able to concatenate two CHAR(1) strings into a VARCHAR2(100).

Moreover the error returned is misleading, it should state &quot;integer overflow&quot; not &quot;numeric overflow&quot;.

As it is, it&#039;s just crazy and quirky.

Flavio]]></description>
		<content:encoded><![CDATA[<p>Even if it&#8217;s expected behaviour, it looks horrible to me.<br />
What about the &#8220;backward compatibility&#8221; concept?<br />
And above all, is there any *real* advantage?<br />
I think that extreme optimization should be knowingly applied by the programmer using an integer variable as destination.<br />
By the same logic, we should not be able to concatenate two CHAR(1) strings into a VARCHAR2(100).</p>
<p>Moreover the error returned is misleading, it should state &#8220;integer overflow&#8221; not &#8220;numeric overflow&#8221;.</p>
<p>As it is, it&#8217;s just crazy and quirky.</p>
<p>Flavio</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Log Buffer #220, A Carnival of the Vanities for DBAs &#124; The Pythian Blog</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40527</link>
		<dc:creator><![CDATA[Log Buffer #220, A Carnival of the Vanities for DBAs &#124; The Pythian Blog]]></dc:creator>
		<pubDate>Mon, 16 May 2011 09:12:12 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40527</guid>
		<description><![CDATA[[...] Jonathan Lewis is in habit of sharing the gems, diamonds and pearls, and yet again shares a little but cute gem. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Jonathan Lewis is in habit of sharing the gems, diamonds and pearls, and yet again shares a little but cute gem. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sokrates</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40525</link>
		<dc:creator><![CDATA[Sokrates]]></dc:creator>
		<pubDate>Mon, 16 May 2011 07:03:13 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40525</guid>
		<description><![CDATA[&lt;cite&gt;
It’s not a bug, it’s expected behaviour. The expression consists of integers only, so Oracle uses INTEGER arithmetic that limits the result to roughly 9 significant figures. If you want the block to work in newer versions of Oracle you have to add a decimal point to (at least) one of the operands to make Oracle use NUMBER arithmetic that takes it up to roughly 38 significant figures.
&lt;/cite&gt;

Hmm, so 
&lt;code&gt;
v1 := cast(256 as number)*256*256*256;
&lt;/code&gt;
should also work  ? 
Let&#039;s try:

&lt;code&gt;
sokrates@11.2.0.2 &gt; declare
  2  v1      number(38);
  3  begin
  4          v1 := cast(256 as number)*256*256*256;
  5          dbms_output.put_line(v1);
  6  end;
  7  /
4294967296

PL/SQL procedure successfully completed.
&lt;/code&gt;

yeah, great !

now, let&#039;s play a bit with the cast-operator and we get:

&lt;code&gt;
sokrates@11.2.0.2 &gt; declare
  2  v1      number(38);
  3  begin
  4          v1 := cast(256 as integer)*256*256*256;
  5          dbms_output.put_line(v1);
  6  end;
  7  /
4294967296

PL/SQL procedure successfully completed.
&lt;/code&gt;

&lt;strong&gt;oops - who can explain that ?&lt;/strong&gt;
looks like a bug again, why does the arithmetic work when I explicitly cast the implicit integer to an integer ??


&lt;/code&gt;
&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p><cite><br />
It’s not a bug, it’s expected behaviour. The expression consists of integers only, so Oracle uses INTEGER arithmetic that limits the result to roughly 9 significant figures. If you want the block to work in newer versions of Oracle you have to add a decimal point to (at least) one of the operands to make Oracle use NUMBER arithmetic that takes it up to roughly 38 significant figures.<br />
</cite></p>
<p>Hmm, so<br />
<code><br />
v1 := cast(256 as number)*256*256*256;<br />
</code><br />
should also work  ?<br />
Let&#8217;s try:</p>
<p><code><br />
sokrates@11.2.0.2 &gt; declare<br />
  2  v1      number(38);<br />
  3  begin<br />
  4          v1 := cast(256 as number)*256*256*256;<br />
  5          dbms_output.put_line(v1);<br />
  6  end;<br />
  7  /<br />
4294967296</p>
<p>PL/SQL procedure successfully completed.<br />
</code></p>
<p>yeah, great !</p>
<p>now, let&#8217;s play a bit with the cast-operator and we get:</p>
<p><code><br />
sokrates@11.2.0.2 &gt; declare<br />
  2  v1      number(38);<br />
  3  begin<br />
  4          v1 := cast(256 as integer)*256*256*256;<br />
  5          dbms_output.put_line(v1);<br />
  6  end;<br />
  7  /<br />
4294967296</p>
<p>PL/SQL procedure successfully completed.<br />
</code></p>
<p><strong>oops &#8211; who can explain that ?</strong><br />
looks like a bug again, why does the arithmetic work when I explicitly cast the implicit integer to an integer ??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carlos</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40524</link>
		<dc:creator><![CDATA[Carlos]]></dc:creator>
		<pubDate>Mon, 16 May 2011 06:54:36 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40524</guid>
		<description><![CDATA[Funny how I had to get used to it when I moved to Teradata and here it is in Oracle... ;-)

Cheers.

Carlos.]]></description>
		<content:encoded><![CDATA[<p>Funny how I had to get used to it when I moved to Teradata and here it is in Oracle&#8230; ;-)</p>
<p>Cheers.</p>
<p>Carlos.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bradd Piontek</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40519</link>
		<dc:creator><![CDATA[Bradd Piontek]]></dc:creator>
		<pubDate>Fri, 13 May 2011 19:59:29 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40519</guid>
		<description><![CDATA[I ran into this issue with some internal code a few years ago and blogged about it on 10g upgrade gotcha&#039;s. Ahh, the memories. Bring on 12c or whatever they will call it.

http://piontekdd.blogspot.com/2008/07/10g-migration-ramification-part-1-ora.html]]></description>
		<content:encoded><![CDATA[<p>I ran into this issue with some internal code a few years ago and blogged about it on 10g upgrade gotcha&#8217;s. Ahh, the memories. Bring on 12c or whatever they will call it.</p>
<p><a href="http://piontekdd.blogspot.com/2008/07/10g-migration-ramification-part-1-ora.html" rel="nofollow">http://piontekdd.blogspot.com/2008/07/10g-migration-ramification-part-1-ora.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Galen Boyer</title>
		<link>http://jonathanlewis.wordpress.com/2011/05/13/overflow/#comment-40518</link>
		<dc:creator><![CDATA[Galen Boyer]]></dc:creator>
		<pubDate>Fri, 13 May 2011 19:18:34 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=6302#comment-40518</guid>
		<description><![CDATA[Yeah, I guess that makes sense.  Sort of like:

DECLARE
   v_str varchar2(1);
BEGIN
   v_str := &#039;A&#039; &#124;&#124; &#039;B&#039;;
END;
/
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 4

WHILE

DECLARE
   v_str varchar2(1);
BEGIN
   v_str := substr(&#039;A&#039; &#124;&#124; &#039;B&#039;,1,1);
END;
/

Does not produce an error.

I guess the rational is that Oracle is trying to stay away from casting the operands of the expression based on the datatype of the result of the expression.  

At the same time, you could make the argument that Oracle has to cast each operand of the expression to something and he is choosing integer because of what the 4 strings looked like (256). So, at the time that Oracle is making the judgement call of what datatype to use, if the result is known to be a more generous datatype than what Oracle would choose, why not make the choice of what to cast to based on the operand datatype of the result?

Oh well.  Thanks for the diversion.  Little tidbits like that are, as you put it, &quot;Gems&quot;.]]></description>
		<content:encoded><![CDATA[<p>Yeah, I guess that makes sense.  Sort of like:</p>
<p>DECLARE<br />
   v_str varchar2(1);<br />
BEGIN<br />
   v_str := &#8216;A&#8217; || &#8216;B&#8217;;<br />
END;<br />
/<br />
ERROR at line 1:<br />
ORA-06502: PL/SQL: numeric or value error: character string buffer too small<br />
ORA-06512: at line 4</p>
<p>WHILE</p>
<p>DECLARE<br />
   v_str varchar2(1);<br />
BEGIN<br />
   v_str := substr(&#8216;A&#8217; || &#8216;B&#8217;,1,1);<br />
END;<br />
/</p>
<p>Does not produce an error.</p>
<p>I guess the rational is that Oracle is trying to stay away from casting the operands of the expression based on the datatype of the result of the expression.  </p>
<p>At the same time, you could make the argument that Oracle has to cast each operand of the expression to something and he is choosing integer because of what the 4 strings looked like (256). So, at the time that Oracle is making the judgement call of what datatype to use, if the result is known to be a more generous datatype than what Oracle would choose, why not make the choice of what to cast to based on the operand datatype of the result?</p>
<p>Oh well.  Thanks for the diversion.  Little tidbits like that are, as you put it, &#8220;Gems&#8221;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
