Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    20

    Question Unanswered: Get certain characters

    How can I get only Phoenix from Phoenix, AZ?
    I have other cities and states on the query but in the same format.

    I've tried substr(a.air_location,-4,4) but I get ", AZ", the opposite of what I need.

    Thanks.

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    extract characters to the left of the comma.
    So how do you determine which character is the comma?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    substr(a.air_location,1,instr(a.air_location,',')-1)
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  4. #4
    Join Date
    Apr 2009
    Posts
    20
    just needed an extra "1" on it:
    substr(a.air_location, 1, instr(a.air_location, ',',1)-1)

    thanks

  5. #5
    Join Date
    Feb 2009
    Posts
    62
    Regular Expressions do the job quite nicely too.
    Code:
    with src as (select 'Phoenix,AZ' col_1 from dual)
    select regexp_substr(col_1,'[^,]+') from src;

Posting Permissions

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