DELIMITER$$
DROP FUNCTION IF EXISTS aritmatika$$
CREATE FUNCTION aritmatika (var1 INT, var2 INT, var3 CHAR(1))
RETURNS FLOAT
BEGIN
DECLARE hasil FLOAT;
IF var3 = '+' THEN
SET hasil = var1 + var2;
ELSEIF var3 = '-' THEN
SET hasil = var1 - var2;
ELSEIF var3 = '*' THEN
SET hasil = var1 * var2;
ELSEIF var3 = '/' THEN
SET hasil = var1 / var2;
END IF;
RETURN hasil;
END$$
SELECT aritmatika (2,3,'+') AS hasil;
DELIMITER$$
DROP FUNCTION IF EXISTS aritmatika2$$
CREATE FUNCTION aritmatika2 (var1 INT, var2 INT, var3 CHAR(1))
RETURNS FLOAT
BEGIN
DECLARE hasil FLOAT;
CASE var3
WHEN '+' THEN SET hasil = var1 + var2;
WHEN '-' THEN SET hasil = var1 - var2;
WHEN '*' THEN SET hasil = var1 * var2;
WHEN '/' THEN SET hasil = var1 / var2;
END CASE;
RETURN hasil;
END$$
SELECT aritmatika2 (2,3,'+') AS hasil;
DROP FUNCTION IF EXISTS aritmatika$$
CREATE FUNCTION aritmatika (var1 INT, var2 INT, var3 CHAR(1))
RETURNS FLOAT
BEGIN
DECLARE hasil FLOAT;
IF var3 = '+' THEN
SET hasil = var1 + var2;
ELSEIF var3 = '-' THEN
SET hasil = var1 - var2;
ELSEIF var3 = '*' THEN
SET hasil = var1 * var2;
ELSEIF var3 = '/' THEN
SET hasil = var1 / var2;
END IF;
RETURN hasil;
END$$
SELECT aritmatika (2,3,'+') AS hasil;
DELIMITER$$
DROP FUNCTION IF EXISTS aritmatika2$$
CREATE FUNCTION aritmatika2 (var1 INT, var2 INT, var3 CHAR(1))
RETURNS FLOAT
BEGIN
DECLARE hasil FLOAT;
CASE var3
WHEN '+' THEN SET hasil = var1 + var2;
WHEN '-' THEN SET hasil = var1 - var2;
WHEN '*' THEN SET hasil = var1 * var2;
WHEN '/' THEN SET hasil = var1 / var2;
END CASE;
RETURN hasil;
END$$
SELECT aritmatika2 (2,3,'+') AS hasil;
0 komentar:
Posting Komentar