【发布时间】:2017-09-06 18:20:31
【问题描述】:
我有一个 stu 表,它有很多列(名称、lname、用户名、密码和其他),我想在每个新用户注册之后或之前插入一个长度为 8 或 6 个数字和字母字符的随机唯一字符串首次登录时每个新用户的密码。 经过多次搜索发现此代码:
declare ready int default 0;
declare rnd_str text;
while not ready do
set rnd_str := lpad(conv(floor(rand()*pow(36,6)), 10, 36), 6, 0);
if not exists (select * from stu where pass = rnd_str) then
set new.pass = rnd_str;
set ready := 1;
end if;
end while;
我尝试通过 phpmyadmin 创建触发器,然后单击 GO 按钮给我一个错误。
谁能帮我解决这个问题?
phpmyadmin 中的错误是这个文本:
“处理您的请求时出现一个或多个错误:
The following query has failed: "CREATE TRIGGER `set_random_8char_pass` BEFORE INSERT ON `stu` FOR EACH ROW declare ready int default 0; declare rnd_str text; while not ready DO set rnd_str := lpad(conv(floor(rand()*pow(36,6)), 10, 36), 6, 0); if not exists (select * from stu where pass = rnd_str) then set new.pass = rnd_str; set ready := 1; end if; end while;"
MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare ready int default 0; declare rnd_str text; while not ready' at line 1
"
谢谢大家
【问题讨论】:
标签: mysql random triggers phpmyadmin passwords