If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to find the length of a BIGINT?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-06-09, 15:43
Yukke Yukke is offline
Registered User
 
Join Date: Jul 2006
Posts: 13
How to find the length of a BIGINT?

I think in order to do this, I have to convert the BIGINT to a varchar first, but how?

Thanks for your help!
Reply With Quote
  #2 (permalink)  
Old 04-06-09, 17:31
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
if you are cocerned about how many bytes a bigint takes, it is always 8 and it can represent a number with 19 digits.
__________________
mota
Reply With Quote
  #3 (permalink)  
Old 04-06-09, 17:56
Yukke Yukke is offline
Registered User
 
Join Date: Jul 2006
Posts: 13
Quote:
Originally Posted by dbamota
if you are cocerned about how many bytes a bigint takes, it is always 8 and it can represent a number with 19 digits.
I have a column in a table that is of type BIGINT. However the values doesnt always have the same number of digits, it can contain 11 or 13 digits (e.g. 91310140001). I need to be able to distinguish which rows contain 11 or 13 digits, which is why I want to find the length.
Reply With Quote
  #4 (permalink)  
Old 04-06-09, 22:12
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
That reminds me of a guy who did this in java:
Code:
if (Boolean.valueOf(someBooleanValue).toString().length() < 5) ...
Don't they teach arithmetics in universities anymore?
Reply With Quote
  #5 (permalink)  
Old 04-06-09, 22:32
ek1975 ek1975 is offline
Registered User
 
Join Date: Sep 2003
Posts: 44
Will this work? SELECT LENGTH(STRIP(CHAR(YOUR_BIGINT_COLUMN))) ...
Reply With Quote
  #6 (permalink)  
Old 04-07-09, 01:44
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by Yukke
I have a column in a table that is of type BIGINT. However the values doesnt always have the same number of digits, it can contain 11 or 13 digits (e.g. 91310140001). I need to be able to distinguish which rows contain 11 or 13 digits, which is why I want to find the length.
When you say number of digits, I assume you are excluding leading zeros?

If that is the case, any value > 99999999999 must have more than 11 "digits" (as you call them).

To distinguish them, you can use the case statement, where clause, if statement in a proc or function, etc.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #7 (permalink)  
Old 04-07-09, 02:28
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
consider using:

FLOOR(LOG10(your_column))+1
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On