473,507 Members | 2,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB2 arithemtic division

Why do I have a zero result on this query for all non-zero rows? Do I
have to declare specifically the precision of ratio division? How do I
do that? And is there a way to make DB2 'ignore' division by zero and
just punch up a 0 result where such division is encountered so that I
can remove the where-clause?

Here's the query, I think it's very clear what I want to do:

select substr(tablespace_name, 1, 120) as TBSPC_NAME, used_pages,
free_pages, (used_pages/free_pages) as ratio
from table (snapshot_tbs_cfg ('MUTANT', -1)) as snapshot_tbs_cfg
where free_pages <0;

and here is the input set....

TBSPC_NAME USED_PAGES FREE_PAGES
---------------- -------------------- --------------------
SYSCATSPACE 0 0
TEMPSPACE1 0 0
USERSPACE1 0 0
SYSTOOLSPACE 0 0
TEMP 0 0
TABLESPACE_TS 31184 230944
SYSTOOLSTMPSPACE 0 0
Sep 19 '06 #1
2 31045
Pakna wrote:
Why do I have a zero result on this query for all non-zero rows?
Simple: you have integer arithmetic here because your input data is integer.

31184 / 230944 = 0.1350

And that results in 0 because the fractions are simply ignored. If you want
to have a the digits behind the decimal separator, you have to convert at
least one of the parameters to FLOAT or DOUBLE:

SELECT DOUBLE(used_pages) / DOUBLE(free_pages)
FROM ...
And is there a way to make DB2 'ignore' division by zero and
just punch up a 0 result where such division is encountered so that I
can remove the where-clause?
Depends on your DB2 version. AFAIK, DB2 for zOS supports that. LUW doesn't.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Sep 19 '06 #2
Knut Stolze wrote:
Pakna wrote:
>Why do I have a zero result on this query for all non-zero rows?

Simple: you have integer arithmetic here because your input data is integer.

31184 / 230944 = 0.1350

And that results in 0 because the fractions are simply ignored. If you want
to have a the digits behind the decimal separator, you have to convert at
least one of the parameters to FLOAT or DOUBLE:

SELECT DOUBLE(used_pages) / DOUBLE(free_pages)
FROM ...
>And is there a way to make DB2 'ignore' division by zero and
just punch up a 0 result where such division is encountered so that I
can remove the where-clause?

Depends on your DB2 version. AFAIK, DB2 for zOS supports that. LUW doesn't.
Yes, now it works perfectly.

Thank you very much, herr Stolze. Your answers are, as always, much
appreciated.

Much abliged, sir!

With regards
Sep 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2110
by: Tim Rowe | last post by:
If I do from __future__ import division then eval(1/2) gives me 0.5 as expected. But if I do print input("enter a sum: ") and enter 1/2 as the sum I get 0 as if I hadn't done the import. I thought...
2
1899
by: Sebastian Haase | last post by:
Hi, I'm interested in having more people in our lab using numarray/NumPy instead of MatLab. For that I have put together a couple useful modules and written many myself. But then I got reminded of...
5
2240
by: Jive | last post by:
I've got a program with Python 2.3 embedded. When I try to run a script containing "from __future__ import division", I get an exception: File "main2.py", line 3 from __future__ import divison...
15
50991
by: joel | last post by:
I have a table which I want to update by dividing one field into another. The update runs with no errors, but the results come out as only a positive integer number. The datatype for the result...
9
12731
by: Marcin | last post by:
How I can make division of two numbers placed in arrays, example: short int a = {2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2}; short int b =...
17
2392
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
10
3160
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
2
3850
by: kermit | last post by:
For a long time,, There has been a discussion of trueFor division versus integer division in Python. I myslef prefer that / be used for integer division since almost always, I want the...
13
7095
by: jamesonang | last post by:
Supposed unsigned int(32 bits) is the largest number that computer can represent with a single variable. Now, i have a big integer ( less than 64 bit, but great than 32 bit) . i represent it by...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.