If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to split string with delimiter ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-09, 11:19
alvincks alvincks is offline
Registered User
 
Join Date: Mar 2004
Posts: 74
How to split string with delimiter ?

Hi All,

can someone guide me how can i split the string with delimiter ?

ie : budget, hotel, Test

how can i use "," as delimiter so that the query can return me with 3 separate string like

result : budget
hotel
Test

Thank you !
Reply With Quote
  #2 (permalink)  
Old 03-10-09, 12:46
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
since you weren't very clear on what you're doing and why, i shall give you the answer without any sort of example of usage --

use the SUBSTRING_INDEX function

pulling the first word is easy, pulling the last word is easy (using -1 as the count), and pulling any of the words in between will require nested invocations

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-10-09, 18:35
alvincks alvincks is offline
Registered User
 
Join Date: Mar 2004
Posts: 74
Hi r937,

the purpose of doing so is to get count on the frequency of similar words to create tag cloud.

can you please enlighten me on how i can use neted invocation, are you imply using while loop and using following condition as filter

1.Scan character by character to check if there have any ","
2.if "," found then substring
3.if no "," found, then return the only word

if the above condition make sense, how can i scan character by character to find "," ?

thank you !
Reply With Quote
  #4 (permalink)  
Old 03-10-09, 18:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
okay, now that i see what you're doing, i realize that it isn't going to be 3 words all the time, is it

you should do this entire process (analysis of words) outside of mysql

for one thing, this will give you much better power over which words to ignore

save each good word in a separate table, with a link to the article that the word is found in
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-10-09, 19:08
alvincks alvincks is offline
Registered User
 
Join Date: Mar 2004
Posts: 74
Yup r937,

it doesn't fix it with lenght of 3 words, i just need to find a way how i can get a word from a string like that

When i extract one word, i will do a insertion to a temporary table and keep repeat until all string are parse.

then only i start count on the frequency.

my first challenge here is to find out how i can scan each "," in a whole string.

thank you !
Reply With Quote
  #6 (permalink)  
Old 03-10-09, 19:38
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
like i said, do ~not~ attempt to do this with mysql
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On