Created
August 10, 2014 13:23
-
-
Save ara-ta3/fbaab9106c896cdfb4f7 to your computer and use it in GitHub Desktop.
SQLでfizzbuzz問題
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE IF NOT EXISTS test_db; | |
USE test_db; | |
CREATE TABLE IF NOT EXISTS unya | |
( | |
id INT(11), | |
message TEXT | |
); | |
DROP PROCEDURE IF EXISTS find_treasure; | |
DELIMITER // | |
CREATE PROCEDURE find_treasure() | |
BEGIN | |
DECLARE id int default 1; | |
DECLARE text TEXT default null; | |
WHILE id <= 100 DO | |
CASE | |
when mod(id,15)= 0 then set text='fizzbuzz'; | |
when mod(id,5) = 0 then set text='buzz'; | |
when mod(id,3) = 0 then set text='fizz'; | |
else set text = id; | |
END CASE; | |
INSERT INTO unya VALUES(id,text); | |
SET id = id + 1; | |
END WHILE; | |
END; | |
CALL find_treasure(); | |
SELECT * FROM unya; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment