To randomly generate string code as follows:
Define a random string method in the MySQL tutorial, and then call this method in the SQL statement.
Random string function definition method:
Select Round (Round (rand (), 4) *10000);
It would be nice not to use the function directly.
If you have to write a function,
Delimiter $$
Create
function Get_rand ()
returns int deterministic
Begin
declare return_no int;
Select Round (Round (rand (), 4) *10000) into Return_no;
return return_no;
end$$
delimiter;
Examples of using random string function methods:
Update demotable set demoname=rand_string where id>23
Direct execution can be done.
I was at the beginning of the test, because I did not add min (id) judgment, the result is half of the time is always query to the first few lines in the table.
The full query statement is:
SELECT * from ' table '
Where ID >= (select floor (ID) from ' table ') + (select min (ID) () () + (()) + (() () + (() () () () + ("()") M ' table '))
Order by ID limit 1;
SELECT *
From ' table ' as T1 join (select round (select MAX (ID) from ' table ') (select min (IDs) from ' tables ')) + (select min () d) from ' table ') as ID) as T2
where T1.id >= t2.id
ORDER by t1.id limit 1;
Finally, in the PHP tutorial, the two statements were queried 10 times,
The former takes 0.147433 seconds.
The latter takes time 0.015130 seconds
That's the way the MySQL rand function implements random numbers.