Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2002
    Posts
    86

    Unanswered: find the length of a string before starting a specified word

    Hi all,
    I am working with db2v7.2 aix I have the table tab1 with column

    COL1
    -----------------------------------------------------------------------------------
    x'123B4B5FFFFFFF2020202020202020202020202020202020 20202020202020202020202020202020'

    I need to find the length of string before 'FFFFFFFF' in my example is

    '123B4B5'
    length is 7

    Thank you for your help

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: find the length of a string before starting a specified word

    what is col1 defined as ? FOR BIT DATA ?

    and

    Can I ask what you are trying to achieve ?

    Cheers

    Sathyaram

    Originally posted by David2002
    Hi all,
    I am working with db2v7.2 aix I have the table tab1 with column

    COL1
    -----------------------------------------------------------------------------------
    x'123B4B5FFFFFFF2020202020202020202020202020202020 20202020202020202020202020202020'

    I need to find the length of string before 'FFFFFFFF' in my example is

    '123B4B5'
    length is 7

    Thank you for your help

  3. #3
    Join Date
    Jul 2002
    Posts
    86

    Re: find the length of a string before starting a specified word

    Originally posted by sathyaram_s
    what is col1 defined as ? FOR BIT DATA ?

    and

    Can I ask what you are trying to achieve ?

    Cheers

    Sathyaram
    Yes it is for bit data and I want to get the length of string in col1 that is prefix of 'FFFFFFFFF' in my example
    COL1
    -----------------------------------------------------------------------------------
    x'123B4B5FFFFFFF2020202020202020202020202020202020 20202020202020202020202020202020'
    the length is 7 (123B4B5).

    Thanks

  4. #4
    Join Date
    Jul 2002
    Posts
    86

    Re: find the length of a string before starting a specified word

    Originally posted by David2002
    Yes it is for bit data and I want to get the length of string in col1 that is prefix of 'FFFFFFFFF' in my example
    COL1
    -----------------------------------------------------------------------------------
    x'123B4B5FFFFFFF2020202020202020202020202020202020 20202020202020202020202020202020'
    the length is 7 (123B4B5).

    Thanks
    OK I fould the solution with POSSTR function

    db2 "select col1,posstr(hex(col1),'F') from tab1"

    COL1 2
    ----------------------------------------------------------------------------------- -----------
    x'123B4B5FFFFFFF2020202020202020202020202020202020 20202020202020202020202020202020' 8

    Thanks

Posting Permissions

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