免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5149 | 回复: 7
打印 上一主题 下一主题

MYSQL中插入某几位固定的随机字符串,望高手给于解答 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-01 23:36 |只看该作者 |倒序浏览
具体要求是在MYSQL表A中插入

前6位固定为123456的16位随机字符串
随机字符串包括字母a-z、A-Z、0-9
其中表A包含字段X、Y、Z


请问SQL语句应该怎么写,请高手帮帮忙十分感谢。

[ 本帖最后由 icecatbing 于 2008-9-1 23:39 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-09-03 14:18 |只看该作者
没人么...好几天了

论坛徽章:
0
3 [报告]
发表于 2008-09-11 11:41 |只看该作者
你在程序里面生成随机字符窜不行吗?

论坛徽章:
0
4 [报告]
发表于 2008-09-13 21:31 |只看该作者
有道理,如果是用程序连接和使用mysql的话
否则,要直接使用的话,还等高手赐教了~~

论坛徽章:
0
5 [报告]
发表于 2008-09-18 19:04 |只看该作者

mysql 生成随机字符串

select concat(
char(round((rand())*25)+97),
char(round((rand())*25)+65),
char(round((rand())*25)+65),
char(round((rand())*25)+97),
char(round((rand())*25)+65),
char(round((rand())*25)+65),
char(round((rand())*25)+97),
char(round((rand())*25)+65)
)

---------

+97就是产生小写字母a-z
+65就是产生大写字母A-Z

结果不包含其他字符

论坛徽章:
0
6 [报告]
发表于 2008-09-18 19:16 |只看该作者
select concat(
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end,
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end,
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end,
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end,
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end,
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end,
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end,
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end,
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end,
case when round((rand())*25) > 12 then char(round((rand())*25)+97) else char(round((rand())*25)+65) end
) as keka

也可用 case when 再混淆大小写。

论坛徽章:
0
7 [报告]
发表于 2008-09-18 22:04 |只看该作者
select CONCAT('123456',
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end,
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end,
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end,
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end,
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end,
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end,
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end,
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end,
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end,
case round((rand())*2) when 0 then round((rand())*9)  when 1 then char(round((rand())*25)+97)  else char(round((rand())*25)+65) end
)

-----------
自己改成insert 就可以了:wink:

论坛徽章:
0
8 [报告]
发表于 2008-10-01 10:45 |只看该作者
select concat('123456',left(replace(uuid(),'-',''),10)) as rand_str;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP