CREATE TABLE inheritance (
derived varchar(50),
base varchar(50)
);
CREATE TABLE variables (
var_name varchar(255),
type varchar(50)
);
INSERT INTO inheritance VALUES ('Double', 'Number');
INSERT INTO inheritance VALUES ('Int', 'Number');
INSERT INTO inheritance VALUES ('Int64', 'Int');
INSERT INTO inheritance VALUES ('Number', 'Object');
INSERT INTO variables VALUES ('A', 'Int');
INSERT INTO variables VALUES ('B', 'Object');
INSERT INTO variables VALUES ('C', 'Double');
INSERT INTO variables VALUES ('E', 'Int64');
INSERT INTO variables VALUES ('E', 'Number');
CREATE PROCEDURE solution()
SELECT var_name, type var_type
FROM variables
WHERE a(type);
CREATE FUNCTION a( c TEXT ) RETURNS INT
LOOP
SET c=(SELECT base FROM inheritance WHERE derived=c);
-- If c is NULL then the query above will not return a row.
-- Any derived type of 'number' will be returned because due to WHERE NOT NULL.
IF c IS NULL OR c = 'NUMBER' THEN
RETURN ORD(c);
END IF;
END LOOP