Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default LIKE, REGEX

    Hi,

    Using the following records :
    PF03001
    PF03002
    PF03003
    PF03004
    PFR03001
    PFR03002
    PFR03003
    PFR03004

    How can I extract only the PF records (and not the PFR ones) using the LIKE
    statement ?
    My first idea was to search for PF and verify that the following char is a
    numeric one :
    "select ... where ID like 'PF[0-9]%'"
    Of course, it does not work :-(

    I'm using an Oracle database !
    I search for regex but did not found a lot !

    TIA

    Patrice


    Patrice FRITSCH Guest

  2. Similar Questions and Discussions

    1. Regex help
      I'd like to replace any html tags containing "< >" with a space. For example, <TR VALIGN=TOP>, I'd like to replace that with a space. Is there a...
    2. REGEX help pls
      in the regex buddy they are explaining: "Be careful when using the negated shorthands inside square brackets. is not the same as . The latter...
    3. Regex..
      Could some good samaritan help me out with this pls... I am trying to find a regular expression for the below string.. ExchangeName =...
    4. Need help with regex
      > I have a directory of files that I want to move to another directory.
    5. IP regex?
      Gareth Glaccum wrote: How about using m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ and testing $1 - $4 for compliance? Much cleaner. -- Cheers,
  3. #2

    Default Re: LIKE, REGEX

    Select MyField from MyTable
    WHERE
    SUBSTRING(MyField, 1, 2) = 'PF')
    AND SUBSTRING(MyField, 1, 3) <> 'PFR')

    "Patrice FRITSCH" <patrice.fritsch@NOSPAM.com> wrote in message
    news:%23l2sFjURDHA.940@TK2MSFTNGP11.phx.gbl...
    > Hi,
    >
    > Using the following records :
    > PF03001
    > PF03002
    > PF03003
    > PF03004
    > PFR03001
    > PFR03002
    > PFR03003
    > PFR03004
    >
    > How can I extract only the PF records (and not the PFR ones) using the
    LIKE
    > statement ?
    > My first idea was to search for PF and verify that the following char is a
    > numeric one :
    > "select ... where ID like 'PF[0-9]%'"
    > Of course, it does not work :-(
    >
    > I'm using an Oracle database !
    > I search for regex but did not found a lot !
    >
    > TIA
    >
    > Patrice
    >
    >

    Brandon Miller Guest

  4. #3

    Default Re: LIKE, REGEX

    How about: Where ID like 'PF%' and ID not like 'PFR%'
    Hmm, might be slow, with two like clauses. Maybe worth a try, at least.

    "Patrice FRITSCH" <patrice.fritsch@NOSPAM.com> wrote in message
    news:#l2sFjURDHA.940@TK2MSFTNGP11.phx.gbl...
    > Hi,
    >
    > Using the following records :
    > PF03001
    > PF03002
    > PF03003
    > PF03004
    > PFR03001
    > PFR03002
    > PFR03003
    > PFR03004
    >
    > How can I extract only the PF records (and not the PFR ones) using the
    LIKE
    > statement ?
    > My first idea was to search for PF and verify that the following char
    is a
    > numeric one :
    > "select ... where ID like 'PF[0-9]%'"
    > Of course, it does not work :-(
    >
    > I'm using an Oracle database !
    > I search for regex but did not found a lot !
    >
    > TIA
    >
    > Patrice
    >
    >

    Kris Eiben Guest

  5. #4

    Default Re: LIKE, REGEX

    Thanks all for your quick answers.
    Your solutions would work for PF & PFR, but I forgot to mention something!!
    SORRY
    In fact, we have always a userid (2 or more chars) followed by a serial
    number. And of course we have hundreds of userId's ! So it may happen that
    one userid starts with the one of another users (in my example PFR & PF).

    So I have to be sure that my fields starts with the usersId + any numeric
    value, that's why I was looking for something like "UserId"[0-9]%

    I'm not sure I'm clear :-(

    "Patrice FRITSCH" <patrice.fritsch@NOSPAM.com> a écrit dans le message de
    news: #l2sFjURDHA.940@TK2MSFTNGP11.phx.gbl...
    > Hi,
    >
    > Using the following records :
    > PF03001
    > PF03002
    > PF03003
    > PF03004
    > PFR03001
    > PFR03002
    > PFR03003
    > PFR03004
    >
    > How can I extract only the PF records (and not the PFR ones) using the
    LIKE
    > statement ?
    > My first idea was to search for PF and verify that the following char is a
    > numeric one :
    > "select ... where ID like 'PF[0-9]%'"
    > Of course, it does not work :-(
    >
    > I'm using an Oracle database !
    > I search for regex but did not found a lot !
    >
    > TIA
    >
    > Patrice
    >
    >

    Patrice FRITSCH Guest

  6. #5

    Default Re: LIKE, REGEX

    > "select ... where ID like 'PF[0-9]%'"
    > Of course, it does not work :-(
    >
    > I'm using an Oracle database !
    This [0-9] syntax will work in SQL Server. I think you need query help from
    an Oracle newsgroup, not an ASP newsgroup!

    A


    Aaron Bertrand - MVP Guest

  7. #6

    Default Re: LIKE, REGEX

    You are absolutely right Ray.
    Unfortunately I have a read-only access to the databases and cannot change
    anything as this tables are used by other applications !!!

    I guess the solution is to verify in my ASP page and not solve the problem
    with a SQL query :-(

    "Ray at <%=sLocation%>" <ask@me.forit> a écrit dans le message de news:
    [email]uNzAcmVRDHA.560@TK2MSFTNGP10.phx.gbl[/email]...
    > I'm not sure you're clear either. [: But it sounds like you have two
    > pieces of independent data stored in a single column, and if that's the
    > case, these kinds of problems are inevitable. Perhaps you should consider
    > splitting the data.
    >
    > Ray at work
    >
    > "Patrice FRITSCH" <patrice.fritsch@NOSPAM.com> wrote in message
    > news:eGI1FKVRDHA.1804@TK2MSFTNGP11.phx.gbl...
    > > Thanks all for your quick answers.
    > > Your solutions would work for PF & PFR, but I forgot to mention
    > something!!
    > > SORRY
    > > In fact, we have always a userid (2 or more chars) followed by a serial
    > > number. And of course we have hundreds of userId's ! So it may happen
    that
    > > one userid starts with the one of another users (in my example PFR &
    PF).
    > >
    > > So I have to be sure that my fields starts with the usersId + any
    numeric
    > > value, that's why I was looking for something like "UserId"[0-9]%
    > >
    > > I'm not sure I'm clear :-(
    > >
    > > "Patrice FRITSCH" <patrice.fritsch@NOSPAM.com> a écrit dans le message
    de
    > > news: #l2sFjURDHA.940@TK2MSFTNGP11.phx.gbl...
    > > > Hi,
    > > >
    > > > Using the following records :
    > > > PF03001
    > > > PF03002
    > > > PF03003
    > > > PF03004
    > > > PFR03001
    > > > PFR03002
    > > > PFR03003
    > > > PFR03004
    > > >
    > > > How can I extract only the PF records (and not the PFR ones) using the
    > > LIKE
    > > > statement ?
    > > > My first idea was to search for PF and verify that the following char
    is
    > a
    > > > numeric one :
    > > > "select ... where ID like 'PF[0-9]%'"
    > > > Of course, it does not work :-(
    > > >
    > > > I'm using an Oracle database !
    > > > I search for regex but did not found a lot !
    > > >
    > > > TIA
    > > >
    > > > Patrice
    > > >
    > > >
    > >
    > >
    >
    >

    Patrice FRITSCH Guest

  8. #7

    Default Re: LIKE, REGEX

    > I guess the solution is to verify in my ASP page and not solve the problem
    > with a SQL query :-(
    Or, see an ORACLE NEWSGROUP to get help with your query?!??!?


    Aaron Bertrand - MVP Guest

  9. #8

    Default Re: LIKE, REGEX

    Well, in theory, it shouldn't matter what the data source is, since SQL is
    the same regardless of what kind of database you're using. You did hear my
    sarcastic tone there, yes? :P

    Ray at work

    "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    news:egg933VRDHA.2676@TK2MSFTNGP10.phx.gbl...
    > > I guess the solution is to verify in my ASP page and not solve the
    problem
    > > with a SQL query :-(
    >
    > Or, see an ORACLE NEWSGROUP to get help with your query?!??!?
    >
    >

    Ray at Guest

  10. #9

    Default Re: LIKE, REGEX

    "Patrice FRITSCH" <patrice.fritsch@NOSPAM.com> wrote in message
    news:eGI1FKVRDHA.1804@TK2MSFTNGP11.phx.gbl...
    > Thanks all for your quick answers.
    > Your solutions would work for PF & PFR, but I forgot to mention
    something!!
    > SORRY
    > In fact, we have always a userid (2 or more chars) followed by a
    serial
    > number. And of course we have hundreds of userId's ! So it may happen
    that
    > one userid starts with the one of another users (in my example PFR &
    PF).
    >
    > So I have to be sure that my fields starts with the usersId + any
    numeric
    > value, that's why I was looking for something like "UserId"[0-9]%
    Use Brandon's solution, but reference UserID instead of hard coding 'PF'

    HTH
    -Chris


    Chris Hohmann Guest

  11. #10

    Default Re: LIKE, REGEX

    Responses inline:
    "Patrice FRITSCH" <patrice.fritsch@NOSPAM.com> wrote in message
    news:unfs9UeRDHA.304@tk2msftngp13.phx.gbl...
    > Hello Chris,
    >
    > It will not work !
    No need to shout.
    > My Sql queryString will be :
    > sqQuery = "Select ...... from MyTable where ID like '" +
    > request.queryString("UserId") + "%'"
    >
    > As the userid coming from my QueryString can have 2 or more chars
    >
    > If I have a userId PH, it will also return the PHB, PHM, PHTI, PH...
    records
    > !
    Every see that Seinfeld episode with Elaine and exclamation points? "I
    would use one here!, and here! and here!"
    > I have modified my asp code to verify that the char following the
    UserId in
    > the ID field is a numeric one.
    >
    > When searching for userId PH, I will also receive the PHB%, PHM%,
    PHTI%
    > records.
    > I just have to test that the 3rd char of the return field is numeric.
    >
    sqQuery = _
    "SELECT ...... FROM MyTable" & vbCRLF &_
    "WHERE ID >= '" & Request.QueryString("UserId") & "0'" & vbCRLF &_
    "AND ID < '" & Request.QueryString("UserId") & ":'"
    > Thank anyway for your help
    > Patrice
    Your welcome.
    -Chris

    P.S. I found this solution in the first hit I got from Google Groups
    using "oracle regular expression" as the search term.


    Chris Hohmann Guest

  12. #11

    Default Re: LIKE, REGEX

    I really have to get out of the habit of replying to my own posts,
    but...

    Here's a really interesting discussion on building regular expression
    support into Oracle.

    [url]http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:2200894550208[/url]



    Chris Hohmann Guest

  13. #12

    Default Re: LIKE, REGEX

    Hello Chris

    I DID NOT SHOUT :-)))

    your solution is excellent.
    Meanwhile I found another solution one using the SUBSTR function.
    "SELECT ... FROM MyTable WHERE ID like '" & szId & "%' AND SUBSTR(ID, " &
    len(szId)+1 & ", 1) IN .......

    I will also have a look at the oracle newsgroup, as the regular expression
    solution can be usefull for other applications.
    Thanks again Chris


    "Chris Hohmann" <hohmannATyahooDOTcom> a écrit dans le message de news:
    [email]uEMuAikRDHA.3700@tk2msftngp13.phx.gbl[/email]...
    > Responses inline:
    > "Patrice FRITSCH" <patrice.fritsch@NOSPAM.com> wrote in message
    > news:unfs9UeRDHA.304@tk2msftngp13.phx.gbl...
    > > Hello Chris,
    > >
    > > It will not work !
    >
    > No need to shout.
    >
    > > My Sql queryString will be :
    > > sqQuery = "Select ...... from MyTable where ID like '" +
    > > request.queryString("UserId") + "%'"
    > >
    > > As the userid coming from my QueryString can have 2 or more chars
    > >
    > > If I have a userId PH, it will also return the PHB, PHM, PHTI, PH...
    > records
    > > !
    >
    > Every see that Seinfeld episode with Elaine and exclamation points? "I
    > would use one here!, and here! and here!"
    >
    > > I have modified my asp code to verify that the char following the
    > UserId in
    > > the ID field is a numeric one.
    > >
    > > When searching for userId PH, I will also receive the PHB%, PHM%,
    > PHTI%
    > > records.
    > > I just have to test that the 3rd char of the return field is numeric.
    > >
    >
    > sqQuery = _
    > "SELECT ...... FROM MyTable" & vbCRLF &_
    > "WHERE ID >= '" & Request.QueryString("UserId") & "0'" & vbCRLF &_
    > "AND ID < '" & Request.QueryString("UserId") & ":'"
    >
    > > Thank anyway for your help
    > > Patrice
    >
    > Your welcome.
    > -Chris
    >
    > P.S. I found this solution in the first hit I got from Google Groups
    > using "oracle regular expression" as the search term.
    >
    >

    Patrice FRITSCH Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139