DBAsupport.com Forums - Powered by vBulletin
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Search for number in varchar column

  1. #1
    Join Date
    Dec 1999
    Location
    Purgatory
    Posts
    346

    Search for number in varchar column

    Hi All,

    I have a varchar2 column 'Address_Line_1' and I need to identify all the rows that have a number somewhere in that column.

    So... 1 Western Avenue ... is selected
    But.. The Manor ... is not selected

    Yes, most Address lines will have a number, but there is a valid reason.

    Can anyone suggest a good way of doing this.

    i was thinking of using translate.....

    Thanks.

  2. #2
    Join Date
    Mar 2002
    Location
    Mesa, Arizona
    Posts
    1,204
    What version are you on? If you're on 10, I'd say using regexp (regular expression) is the way to go...

  3. #3
    Join Date
    May 2005
    Location
    Toronto Canada
    Posts
    57
    If you can't use regexp, I would be inclined to go with something like:

    Code:
    SELECT col FROM t
    WHERE INSTR(col, '1') <> 0 or
          INSTR(col, '2') <> 0 or
          INSTR(col, '3') <> 0 or
          INSTR(col, '4') <> 0 or
          INSTR(col, '5') <> 0 or
          INSTR(col, '6') <> 0 or
          INSTR(col, '7') <> 0 or
          INSTR(col, '8') <> 0 or
          INSTR(col, '9') <> 0
    You are going to be full scanning anyway, at least the ORs will short circuit on the evaluation.

    John

  4. #4
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Code:
    select col from t
    where instr(translate(col,'123456789','000000000'),'0') > 0
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  5. #5
    Join Date
    Dec 1999
    Location
    Purgatory
    Posts
    346
    Thanks Guys,

    Tried both, same plan, more or less the same timings BUT John's code returns 48,333,191 rows and Dave's code returns 48,334,913 rows.

    I'm having trouble spotting the difference......... Help !!

  6. #6
    Join Date
    Nov 2001
    Location
    The Netherlands
    Posts
    19
    Hi,

    probably the 0's. John didn't have them in the OR.

    Regards,

    Arian

  7. #7
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    W00t!
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  8. #8
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    When in doubt, slimdave is always right.
    Jeff Hunter

  9. #9
    Join Date
    Nov 2001
    Location
    The Netherlands
    Posts
    19
    W00t!


    Am I getting old already?

  10. #10
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Quote Originally Posted by marist89
    When in doubt, slimdave is always right.
    ... especially about politics.
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

Posting Permissions

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


Click Here to Expand Forum to Full Width