By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,558 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,558 IT Pros & Developers. It's quick & easy.

Datatype for creating a range value in db2

P: n/a
Hi

I would like to have an attribute that would store an integer or float
range (say 6 to 10). Is it possible to have both the lower and upper
limit specified in a single field?

Thanks
Mahesh

Apr 26 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mahesh S wrote:
I would like to have an attribute that would store an integer or float
range (say 6 to 10). Is it possible to have both the lower and upper
limit specified in a single field?

Not sure what you mean.
Attributes are elements of structured types. Are you talking about a
structured type?
CREATE TYPE address AS (no INTEGER, street VARCHAR(30))
and you you want to constrain the attribute?
You can't do this as part of CREATE TYPE, but you can overload the
"mutator" and "constructor" to constrain what can be set.

Or are you talking about a column rather than attribute?
CREATE TABLE T(c1 float check (c1 between 6 and 10))

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 26 '06 #2

P: n/a
Hi Serge

Well, let me clarify my question. What I would like to have is a
single field that stores a range value instead of a single number. For
instance, normally, you would store in an int field, say value 5. What
I want to do instead is store the value [6, 10] inside a field which
represents a range rather than a single value. Is that making any
sense? Are there any structured types available that would let me
store a range instead of a single value. I hope you are familiar with
this math notation [6,10] which implies all values between and
including 6 and 10.

Thanks
Mahesh

Apr 27 '06 #3

P: n/a
Mahesh S wrote:
Hi Serge

Well, let me clarify my question. What I would like to have is a
single field that stores a range value instead of a single number. For
instance, normally, you would store in an int field, say value 5. What
I want to do instead is store the value [6, 10] inside a field which
represents a range rather than a single value. Is that making any
sense? Are there any structured types available that would let me
store a range instead of a single value. I hope you are familiar with
this math notation [6,10] which implies all values between and
including 6 and 10.

You could create your own structured type "range"
with, say, 4 attributes: lower bound, upper bound, inclusive_low,
inclusive_high.
OO is pretty haavy stuff and therefore not exactly popular outside of
academia.
I'm wondering why you would go through these lengths instead of simply
storing the base information in the table.
Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 27 '06 #4

P: n/a
yes, that does sound complicated.. will opt for the easy way out..
thanks..

Apr 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.