IT Community - Software Programming, Web Development and Technical Support

Loop in Mysql

This is a discussion on Loop in Mysql within the Database Support forums, part of the Web Development category; hi techies, The following code will work upto 100 loops.. You may add one more join will get 1000 loops... ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-12-2008, 06:37 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Loop in Mysql

hi techies,

The following code will work upto 100 loops..
You may add one more join will get 1000 loops...

Code:
SET @string:='one,tow,three,four,five,six,seven,eight,nine,ten';
SET @row:=0;
SET @length:=LENGTH(@string)-LENGTH(REPLACE(@string,',',''))+1;
SET @from_clause:=CONCAT('SELECT 1 ',REPEAT(' UNION ALL SELECT 1 ',9));

SET @sql:=CONCAT("
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(@string,',',@row:=@row+1),',',-1) AS numbers 
FROM (",@from_clause,")a JOIN (",@from_clause," )b LIMIT ",@length);

PREPARE st FROM @sql;
EXECUTE st;
OUTPUT
Code:

numbers	
----------
one	
tow	
three	
four	
five	
six	
seven	
eight	
nine	
ten
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i do loop testing manually? sundarraja Software Testing 1 07-25-2007 01:02 AM
Javaa:Tutorial - The Loop pranky Java Programming 0 02-24-2007 12:58 AM


All times are GMT -7. The time now is 03:30 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0