CREATE SCHEMA IF NOT EXISTS common_schema;
|
DELIMITER $$
|
DROP FUNCTION IF EXISTS common_schema.add_ints $$
|
CREATE FUNCTION common_schema.add_ints(int_1 INT, int_2 INT) RETURNS INT NO SQL
|
BEGIN
|
RETURN int_1 + int_2;
|
END $$
|
DROP FUNCTION IF EXISTS common_schema.sum_ints $$
|
CREATE AGGREGATE FUNCTION common_schema.sum_ints(int_val INT) RETURNS INT
|
BEGIN
|
DECLARE result INT DEFAULT 0;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN result;
|
LOOP FETCH GROUP NEXT ROW;
|
SET result = common_schema.add_ints(result, int_val);
|
END LOOP;
|
END $$
|
|
DELIMITER ;
|