新手,在线等。。while语句怎么写??

wylwyl1108 2015-03-15 12:25:10
为什么百度上都是要加存储过程???
而且我加了存储过程还是错的。。。

比如我set @a=1 select @a
直接结果为1

现在我做个做简单的
while @a<5 do
select @a;
set @a=@+1;
end while;
...全文
110 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
技术狼 2015-03-15
  • 打赏
  • 举报
回复

begin

  declare i int default 0;

  while i < 40 do

    insert into users(userID,userName,password) values(i,concat('username',i),concat('password',i));

    set i = i + 1;

  end while;

end

ACMAIN_CHM 2015-03-15
  • 打赏
  • 举报
回复
分享一个技巧,任何软件的官方手册都是最好的找答案的去处。 下载MYSQL官方免费手册,打开手册,然后搜索 while ,秒杀,就可以找到答案。
引用
12.8.6.7. WHILE Statement [begin_label:] WHILE search_condition DO statement_list END WHILE [end_label] The statement list within a WHILE statement is repeated as long as the search_condition is true. statement_list consists of one or more statements. A WHILE statement can be labeled. end_label cannot be given unless begin_label also is present. If both are present, they must be the same. Example: CREATE PROCEDURE dowhile() BEGIN DECLARE v1 INT DEFAULT 5; WHILE v1 > 0 DO ... SET v1 = v1 - 1; END WHILE; END

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧