MySQL中随机生成固定长度字符串的方法
时间:2024-01-12 13:04:20
要随机生成字符串代码如下:
在MySQL中定义一个随机串的方法,然后再SQL语句中调用此方法。
随机串函数定义方法:
CREATE DEFINER=`root`@`localhost` FUNCTION `rand_string`(n INT) RETURNS varchar(255) CHARSET latin1
BEGIN
DECLARE chars_str varchar(100) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
DECLARE return_str varchar(255) DEFAULT '';
DECLARE i INT DEFAULT 0;
WHILE i < n DO
SET return_str = concat(return_str,substring(chars_str , FLOOR(1 + RAND()*62 ),1));
SET i = i +1;
END WHILE;
RETURN return_str;
END;
使用随机串函数方法示例:
UPDATE demotable SET demoname=rand_string(32) WHERE id>23
直接执行即可。
标签:固定长度,字符串
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
VUEJS实战之构建基础并渲染出列表(1)
2024-05-29 22:14:46
![](https://img.aspxhome.com/file/2023/5/123185_0s.jpg)
ORACLE LATERAL-SQL-INJECTION 个人见解
2009-03-04 10:34:00
安装MSSql2005时 “以前的某个程序安装已在安装计算机上创建挂起” 的解决办法
2024-01-22 08:49:39
python实现npy格式文件转换为txt文件操作
2021-04-03 08:07:05
![](https://img.aspxhome.com/file/2023/5/92075_0s.jpg)
深入理解Python单元测试unittest的使用示例
2022-03-18 04:51:00
![](https://img.aspxhome.com/file/2023/2/92412_0s.png)
Google logo “我的中国”谷歌国际少年绘画大赛小学1-3年级
2008-12-19 12:26:00
![](https://img.aspxhome.com/file/UploadPic/200812/19/j1-3_01-72s.jpg)
python字符串不可变数据类型
2021-04-14 23:07:09
MySQL内建复制功能来优化可用性
2010-10-25 20:20:00
SQL Server在AlwaysOn中使用内存表的“踩坑”记录
2024-01-26 03:49:10
![](https://img.aspxhome.com/file/2023/2/96212_0s.png)
Python爬取豆瓣数据实现过程解析
2022-01-27 09:12:20
![](https://img.aspxhome.com/file/2023/2/86252_0s.png)
python3 lambda表达式详解
2021-03-01 20:28:20
Python中的pathlib库使用详解
2023-07-22 02:09:24
![](https://img.aspxhome.com/file/2023/9/131059_0s.jpg)
Python实现图片滑动式验证识别方法
2023-11-05 22:14:52
![](https://img.aspxhome.com/file/2023/3/94183_0s.png)
python代理工具mitmproxy使用指南
2021-06-17 14:15:31
![](https://img.aspxhome.com/file/2023/3/125013_0s.jpg)
Python图像处理模块ndimage用法实例分析
2023-09-08 16:52:26
![](https://img.aspxhome.com/file/2023/6/100816_0s.png)
spring使用RedisTemplate操作Redis数据库
2024-01-16 03:32:28
![](https://img.aspxhome.com/file/2023/4/89644_0s.png)
ASP日期格式化函数
2010-08-08 19:18:00
两个asp函数实现javascript的escape函数和unescape函数功能
2009-02-04 15:47:00
白鸦:内容设计,初始内容
2008-03-04 16:23:00
JS获取select的value和text值的简单实例
2024-04-19 09:50:11