Results 1 to 4 of 4

Thread: How to get a part of the string ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    How to get a part of the string ?

    How can i get

    1 out of '1 - Jack' or
    26 out of '26 - Dave' or
    436 out of '436 - Michael' ???

    There is a blank space on either side of Hiphen (_-_). I want to get the numeric part of the string only, be it 1 digit 2 digit or whatever...

    I am using Oracle9i SQLplus.

  2. #2
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Smile Re: How to get a part of the string ?

    hi

    i have never used Oracle, but in SQL we do it like this. If i want to get


    lets Assume you have a Field "Description" and it Contains

    '1 - Jack' And from this you want to Extract 1
    Code:
    
    select substring(Description,1,1)
    from MyTable
    Its Simple you see

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to get a part of the string ?

    I don't know about Oracle syntax, but for SQL Server you could use something like this:

    Left(fieldname, CharIndex(fieldname,' ') -1 )
    Last edited by si_the_geek; Jan 16th, 2008 at 06:36 AM. Reason: added -1 after being reminded by the post below!

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: How to get a part of the string ?

    Ditto on Oracle, also

    Left(fieldname, Instr(fieldname, ' ') - 1)
    Tengo mas preguntas que contestas

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