Help us understand the problem. What is going on with this article?

Firebird SQL のストアドプロシージャで FizzBuzz

More than 1 year has passed since last update.

はじめに

これは FizzBuzz Advent Calendar 2017 13 日目の記事となります。
Firebird SQL のストアドプロシージャで FizzBuzz を書いてみます。

コード

適当な DB を用意し、ストアドプロシージャを書きます。

SET TERM ^;

CREATE PROCEDURE FizzBuzz
RETURNS
  (Result VARCHAR(10))
AS
  DECLARE VARIABLE I INTEGER = 0;
BEGIN
  WHILE (I < 100) DO
    BEGIN
      I = I + 1;
      IF ((mod(I, 3) = 0) and (mod(I, 5) = 0)) THEN
        Result = 'Fizz Buzz';
      ELSE
        BEGIN
          IF (mod(I, 3) = 0) THEN
            Result = 'Fizz';
          ELSE
            BEGIN
              IF (mod(I, 5) = 0) THEN
                Result = 'Buzz';
              ELSE
                Result = CAST(I as VARCHAR(10));
            END
        END
      SUSPEND;
    END
END ^

SET TERM ;^

次に Select 文を実行します。

Select * from FizzBuzz;

するとこうなります。

image.png

多分 Interbase でも同じコードで OK だと思います。

おわりに

ブラッシュアップしてくれると嬉しいな > Firebird の偉い人。
他の DB のストアドプロシージャではどうなるのかも知りたかったり...。

Firebird Advent Calendar 2017 が開催されていますので興味のあるかたはどうぞ!

See Also:

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした