【发布时间】:2016-11-29 13:44:04
【问题描述】:
我有任务,让程序确定可被 3 和 2 整除的数字,但我只能尝试被 3 和 2 整除,就像这样
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `divisible`()
BEGIN
declare str VARCHAR(255) default '';
declare x INT ;
SET x = 1;
set str = '';
while x <= 100 do
if (x mod 3=0 && x mod 2 =0) then
set str= CONCAT(str, x ,',') ;
end if;
set x=x+1;
end while;
SELECT str ;
END
上述程序的输出:'6,12,18,24,30,36,42,48,54,60,66,72,78,84,90,96,'
如何产生不同的输出,因此可以被 3 整除:3,6,9,12 ... 和 2:1-100 之间的 2,4,6,8。
【问题讨论】:
-
问题是什么?程序看起来还可以。请阅读How-to-Ask 这里是START 了解如何提高问题质量并获得更好答案的好地方。
-
你可以通过简单的查询为什么需要程序来做到这一点
-
@jaidutt 我没有看到一个简单的查询。也许您可以将其显示为答案
-
@jaidutt 我的任务,所以我必须遵守规则
-
哇!最糟糕的 SQL 用法。曾经!! :-)
标签: mysql loops stored-procedures