Unix Technical Forum

strange SQL behaviour

This is a discussion on strange SQL behaviour within the DB2 forums, part of the Database Server Software category; --> Hello, I am running DB2 v7.2 on NT. suppose I ussue following simple SQL stmt: select 3/18*18, dec(3,8,3)/dec(18,8,3)*dec(18,8,3), dec(3,31,8)/dec(18,31,8)*dec(18,31,8), ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 02:40 PM
platho
 
Posts: n/a
Default strange SQL behaviour


Hello,



I am running DB2 v7.2 on NT.



suppose I ussue following simple SQL stmt:



select

3/18*18,

dec(3,8,3)/dec(18,8,3)*dec(18,8,3),

dec(3,31,8)/dec(18,31,8)*dec(18,31,8),

dec(3,30,8)/dec(18,30,8)*dec(18,30,8)

from sysibm.sysdummy1



The results are





3



1.8



Why doesn't the dec(..,31,8) give the correct result ?

Can anyone explain this ?

30,8 works. 29,8 works, ........





Thanks in advance





Peter


--
Posted via http://dbforums.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 02:43 PM
Tokunaga T.
 
Posts: n/a
Default Re: strange SQL behaviour

That worked exactly as designed.
Please see "SQL Reference, Chapter 2. Language elements, Expressions
with arithmetic operatiors"

SELECT *
FROM (VALUES
('1. Operands', 'Integer', 'DEC(8,3)', 'DEC(31,8)',
'DEC(30,8)')
, ('31. Result'
, CHAR(3/18*18)
, CHAR(dec(3, 8,3)/dec(18, 8,3)*dec(18, 8,3))
, CHAR(dec(3,31,8)/dec(18,31,8)*dec(18,31,8))
, CHAR(dec(3,30,8)/dec(18,30,8)*dec(18,30,8))
)
, ('21. Mid Result'
, CHAR(3/18)
, CHAR(dec(3, 8,3)/dec(18, 8,3))
, CHAR(dec(3,31,8)/dec(18,31,8))
, CHAR(dec(3,30,8)/dec(18,30,8))
)
, ('20. DEC(p,s)/DEC(p'',s'') -> DEC(31 , 31-p-s+s'')'
, 'Large integer'
, '(8,3)/(8,3)->DEC(31,23)'
, '(31,8)/(31,8)->DEC(31,0)'
, '(30,8)/(30,8)->DEC(31,1)'
)
, ('30. DEC(p,s)*DEC(p'',s'') -> DEC(min(31,p+p'') ,
min(31,s+s''))'
, 'Large integer'
, '(31,23)*(8,3)->DEC(31,26)'
, '(31,0)*(31,8)->DEC(31,8)'
, '(31,1)*(30,8)->DEC(31,9)'
)
) AS t
ORDER BY 1
;
---------------------------------------------------

1 2
3 4
5
-----------------------------------------------------------
------------- ---------------------------------
--------------------------------- ---------------------------------
1. Operands Integer
DEC(8,3) DEC(31,8)
DEC(30,8)
20. DEC(p,s)/DEC(p',s') -> DEC(31 , 31-p-s+s') Large
integer (8,3)/(8,3)->DEC(31,23) (31,8)/(31,8)->DEC(31,0)
(30,8)/(30,8)->DEC(31,1)
21. Mid Result 0
00000000.16666666666666666666666 0000000000000000000000000000000.
000000000000000000000000000000.1
30. DEC(p,s)*DEC(p',s') -> DEC(min(31,p+p') , min(31,s+s')) Large
integer (31,23)*(8,3)->DEC(31,26) (31,0)*(31,8)->DEC(31,8)
(31,1)*(30,8)->DEC(31,9)
31. Result 0
00002.99999999999999999999988000 00000000000000000000000.00000000
0000000000000000000001.800000000

5 record(s) selected.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:14 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com