I have a hierarchical relational database with taxonomies of different organisms. I have a total of 7 tables where each has a FK pointing to the table "right above". I need to create a function that recieves the "Common Name" of the organism and returns the Kindgom to whom it belongs. Below is my code on MySQL.
CREATE FUNCTION get_Kingdom(@Temp AS VARCHAR(1000)) RETURNS VARCHAR(1000)
AS
BEGIN
DECLARE @ReturnKingdom AS VARCHAR(1000)
SET @ReturnKingdom = (SELECT kingdom.description as descriptionKingdom
FROM Kingdom
JOIN Phylum
ON Kingdom.idKingdom = phylum.Kingdom_idKingdom
JOIN Class
ON Phylum.idPhylum = Class.Phylum_idPhylum
JOIN Order
ON Class.idClass = Order.Class_idClass
JOIN Family
ON Order.idOrder = Family.Order_idOrder
JOIN Genus
ON Family.idFamily = Genus.Family_idFamily
JOIN Species
ON Genus.idGenus = Species.Genus_idGenus
WHERE Species.CommonName = @Temp)
RETURN @ReturnKingdom;
END;
But when I try to call the function
select get_Kingdom('Dog');
I'm getting an error:
'fnc_get_reino' is not a recognized built-in function name.
Any ideas why this is happening?