为了生成10个字符串,我们可以使用内置函数“ rand()”和“ char()”。以下是查询以生成随机的10个字符串。
mysql> SELECT concat( - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97), - > char(round(rand()*25)+97) - > )AS Random10CharacterString;
这是显示随机10个字符串的输出。
+-------------------------+ | Random10CharacterString | +-------------------------+ | duscikyspy | +-------------------------+ 1 row in set (0.00 sec)
以下是生成大写随机字符的查询。
mysql> select concat( - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65), - > char(round(rand()*25)+65) - > )AS Random10CharacterString;
以下是输出。
+-------------------------+ | Random10CharacterString | +-------------------------+ | WMWWVOIXPF | +-------------------------+ 1 row in set (0.00 sec)
上面的输出以大写形式显示随机字符。