SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Split value field

    Hi all.

    I need your help.

    In the field "mem" (varchar 255) of MySql table_name, I have this value:

    Code:
    .Mem C..For A..Gia A..Cir G.
    I need this output:

    Code:
    .Mem C
    For A
    Gia A
    Cir G.
    And try this query:

    Code:
    SELECT split(mem, "..")
    FROM table_name
    But I receive this error:
    FUNCTION dbase.split does not exist

    Can you help me?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    SET @str='.Mem C..For A..Gia A..Cir G.';
    
    SELECT SUBSTRING_INDEX(@str,'..', 1)
    UNION ALL
    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(@str,'..', 2),'..', -1)
    UNION ALL
    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(@str,'..', 3),'..', -1)
    UNION ALL
    SELECT SUBSTRING_INDEX(@str,'..', -1)
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    Code:
    SET @str='.Mem C..For A..Gia A..Cir G.';
    
    SELECT SUBSTRING_INDEX(@str,'..', 1)
    UNION ALL
    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(@str,'..', 2),'..', -1)
    UNION ALL
    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(@str,'..', 3),'..', -1)
    UNION ALL
    SELECT SUBSTRING_INDEX(@str,'..', -1)
    Thanks.


Bookmarks

Posting Permissions

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