IT Community - Software Programming, Web Development and Technical Support

MySql Random string

This is a discussion on MySql Random string within the Database Support forums, part of the Web Development category; Hi buddies, Is there any built in function available in mysql for generating random string. ? There are few functions like ...


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

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-13-2007, 12:36 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default MySql Random string

Hi buddies,

Is there any built in function available in mysql for generating random string. ?

There are few functions like MD5(), SHA() may be used for this purpose, but the throughput of these functions are with the combination of numeric and alphabets. what i need is that i want the random string in alphabets with upper and lower case combination.
__________________
Keep smiling...

Last edited by priyan : 07-13-2007 at 12:39 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-13-2007, 06:03 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 Re: MySql Random string

Hi Priyan,

As per my idea, only possibility to create your own Stored Function / Stored Procedure for Returning random string in alphabets with upper and lower case combination.

Me too wait for any other reply.
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-13-2007, 07:00 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: MySql Random string

Hi murali,

I got it thru stored function... here it's .. but what i m looking is that built-in function for this.. We hope that this utility may be available in future mysql releases.


/* *************************************************
Purpose : To get the random string (only alphabets)
Input : Length of the randon string required (pmStringlength)
************************************************** */
CREATE FUNCTION get_random_string(pmStringlength INTEGER) RETURNS VARCHAR(100)
DETERMINISTIC
BEGIN
DECLARE vString_length INTEGER;
DECLARE vReturn_string VARCHAR(100) DEFAULT '';
DECLARE vTemp1 INTEGER;
DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN RETURN -99; END;

SET vString_length = pmStringlength;

-- Loop will execute to the no of characters given in input
WHILE vString_length > 0 DO
-- Getting a random number between 65 and 122
SET vTemp1 = FLOOR( 65 + (RAND() * 57));
IF (vTemp1 >= 90 AND vTemp1 <= 96) THEN
SET vTemp1 = vTemp1 + 10;
END IF;
-- Changing the random number into character and concatenate
SET vReturn_string = CONCAT(vReturn_string,CHAR(vTemp1));
SET vString_length = vString_length - 1;
END WHILE;
-- Return result
RETURN vReturn_string;
END;

/**************************************/

SELECT get_random_string(10);
Result : eOrcWKhxko

SELECT get_random_string(105)
Result : qSDTgeqspfwToBkcoNmIdmbjyQhgqNegiJPoRDUfLCakCypJTK uCeKiHEwbCdEDGUdJhCgPSmuPdSibmLdfcirivjASeKydOtmKa
__________________
Keep smiling...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-13-2007, 07:31 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 Re: MySql Random string

Yes.

At Present in MYSQL 5.0 the only possiblity is creating our owned defined objects for generating the Random String as per ur point[Only with Characters].

But we expect this and more features in the forthcoming MYSQL Versions.
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
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

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/database-support/1632-mysql-random-string.html
Posted By For Type Date
MySql Random string | Web Hosting This thread Refback 03-06-2008 10:23 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare a string with String Array. oxygen C# Programming 5 12-28-2007 10:18 PM
What is diffrenece between string.compare and string.compareordinal shaalini ASP and ASP.NET Programming 3 12-28-2007 09:46 PM
To get random number in mysql Murali Database Support 7 11-05-2007 10:34 PM
How to split a string by using a string usually in the c# dotnet... Archer C# Programming 1 07-25-2007 02:26 AM
How to set Random image selector in asp.net ? kingmaker ASP and ASP.NET Programming 1 07-23-2007 05:31 AM


All times are GMT -7. The time now is 09:26 PM.


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

SEO by vBSEO 3.0.0