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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 do I generate a random number from php? | itbarota | PHP Programming | 2 | 09-25-2007 07:57 AM |
| How to split a string by using a string usually in the c# dotnet... | Archer | C# Programming | 1 | 07-25-2007 02:26 AM |
Our Partners |