1. Registered User
Join Date
Oct 2004
Posts
5

Hi,

Im using a couple of db2 tables, but i want to find the size of one row.
It has some CHAR, FLOAT and DEC FIXED in there.

Is there a way to calculate how long the row is (by adding all columns)?

Regards

2. Registered User
Join Date
Oct 2004
Location
Norway
Posts
53
SELECT
RECLENGTH
FROM
SYSIBM.SYSTABLES
WHERE
NAME = 'NAMEOFTHETABLE';

---

/pF

3. Registered User
Join Date
Oct 2004
Posts
5
Hi,

the statement doesn't work, but i think it is because i use temporary db2 tables. but i think i can calculate the length myself, but i can't find the lenght that a float represents.

Regards

4. Registered User
Join Date
Oct 2004
Location
Norway
Posts
53
It really depends on whether you CREATE the temp table (Stored in Catalog) or DECLARE it (Not stored in Catalog).

---

/pF

5. Registered User
Join Date
Oct 2004
Posts
5
I declare the table, here is a small example.

DECLARE GLOBAL TEMPORARY TABLE tab1
(var1 float NOT NULL,
var2 char(16) NOT NULL,
var3 decimal (15,2) NOT NULL);

I think that the char(16) has a length of 16 and that decimal (15,2) has a length of 15 but i have no idea about the float.

regards

6. Registered User
Join Date
Oct 2004
Location
Norway
Posts
53
Well, it's rather more difficult than that.

Here is a link that basically describes how they are stored in v. 8.x:

http://publib.boulder.ibm.com/infoce...jnqmstr179.htm

---

/pF

7. Registered User
Join Date
Oct 2004
Posts
5
so if i have it correct

a float has length 8
a char(n) has length n
a decimal(15,2) has length 4

regards

8. Registered User
Join Date
May 2003
Location
USA
Posts
5,737
A decimal(15,2) has an internal length of 8. This is (n +1)/2, rounded to next highest number if not an integer value. So it is (15+1)/2 = 8.

DB2 integers have an internal length of 4. Small integers have an internal length of 2.

Don't forget to add one byte for all nullable columns, and 2 more bytes for any column defined as varchar. The space used by the varchar itself depends on the data in it, so you would have to estimate an average length.
Last edited by Marcus_A; 10-25-04 at 11:22.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•