SQLize Online / PHPize Online

A A A
Share   Donate   Blog   Popular
Copy Format Clear
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 FUNCTION is_base_number_type(type VARCHAR(50)) RETURNS BOOLEAN BEGIN DECLARE base_type VARCHAR(50) DEFAULT ''; DECLARE cur_type VARCHAR(50) DEFAULT NULL; DECLARE result BOOLEAN DEFAULT FALSE; DECLARE i INT DEFAULT 0; SET cur_type = type; SET result = FALSE; SET i = 0; WHILE i < 100 AND (! result) AND (SELECT COUNT(base) FROM inheritance WHERE derived = cur_type LIMIT 1) DO SELECT base INTO base_type FROM inheritance WHERE derived = cur_type LIMIT 1; SET result = IF(IFNULL(base_type, '') = 'Number', TRUE, FALSE); SET cur_type = base_type; SET i = i+1; END WHILE; RETURN result OR i > 50; END; CREATE PROCEDURE solution() BEGIN SELECT var_name, type as var_type FROM variables WHERE is_base_number_type(type); END
Stuck with a problem? Need help? Ask professionals on our Telegram channel!
Join the channel
Your quersion is posted.
Join our Telegram channel and get answers.
Send
Copy