MySQL代码示例:随机密码的生成

原创|其它|编辑:郝浩|2009-09-21 13:52:28.000|阅读 470 次

概述:本文是一篇MySQL随机密码生成的代码示例。

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

  DELIMITER $$
  CREATE
  FUNCTION `t_girl` . `func_rand_string` ( f_num tinyint unsigned , f_type tinyint unsigned )
  RETURNS varchar ( 32)
  BEGIN
  -- Translate the number to letter.
  -- No 1 stands for string only.
  -- No 2 stands for number only.
  -- No 3 stands for combination of the above.
  declare i int unsigned default 0;
  declare v_result varchar ( 255) default '' ;
  while i < f_num do
  if f_type = 1 then
  set v_result = concat ( v_result, char ( 97+ ceil( rand ( ) * 25) ) ) ;
  elseif f_type= 2 then
  set v_result = concat ( v_result, char ( 48+ ceil( rand ( ) * 9) ) ) ;
  elseif f_type= 3 then
  set v_result = concat ( v_result, substring ( replace ( uuid ( ) , '-' , '' ) , i+ 1, 1) ) ;
  end if;
  set i = i + 1;
  end while;
  return v_result;
  END $ $
  DELIMITER ;

  调用方法示例:

  select func_rand_string(12,3);


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:IT专家网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP