Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2006
    Posts
    13

    Unanswered: 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!

  2. #2
    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

  3. #3
    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.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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?
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    Join Date
    Sep 2003
    Posts
    44
    Will this work? SELECT LENGTH(STRIP(CHAR(YOUR_BIGINT_COLUMN))) ...

  6. #6
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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

  7. #7
    Join Date
    Dec 2005
    Posts
    273
    consider using:

    FLOOR(LOG10(your_column))+1

Posting Permissions

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