FizzBuzz in PL/SQL

  • by

The FizzBuzz test is a classic interview programming problem that’s easy to solve if you’re familiar with looping and some sort of MOD function. Here’s an easy solution to the problem in PL/SQL.

Write a program that prints the numbers from 1 to 100.

But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”.

For numbers which are multiples of both three and five print “FizzBuzz”.

BEGIN
    FOR i IN 1..100 LOOP
        IF REMAINDER(i,3) = 0 AND REMAINDER(i,5) = 0 THEN
            dbms_output.put_line('FizzBuzz');
        ELSIF REMAINDER(i,3) = 0 THEN
            dbms_output.put_line('Fizz');
        ELSIF REMAINDER(i,5) = 0 THEN
            dbms_output.put_line('Buzz');
        ELSE
            dbms_output.put_line(i);
        END IF;
    END LOOP;
END;

Leave a Reply

Your email address will not be published. Required fields are marked *