私は、2 つのレシピ間の類似性を計算する PL/SQL スクリプトに取り組んできました。 レシピは、すべてのタイトル、準備などを含むテーブルです。材料は、すべての固有の材料が格納される場所であり、レシピは、多対多の問題が解決される場所であり、2 つがリンクされています。
CREATE OR REPLACE FUNCTION func_similarity
(idS1 IN recipes.recipe.recipeID%type , idS2 IN recipes.recipe.recipeID%type )
RETURN NUMBER
AS
sim_value NUMBER := 0;
BEGIN
SELECT 2*
(select count(*) from recipes.ingredient i where i.ingredientID in (
Select distinct ingredientID from recipes.recipeing where recipeID = s1.recipeID
intersect
select distinct ingredientID from recipes.recipeing where recipeID = s2.recipeID))
/ ((select distinct count(ingredientID) from RECIPES.recipeing where recipeID = s1.recipeID) +
(select distinct count(ingredientID) from recipes.recipeing where recipeID = s2.recipeID) ) INTO sim_value
from recipes.recipe s1, recipes.recipe s2
where s1.recipeID = idS1
and s2.recipeID = idS2;
RETURN (sim_value);
END func_similarity;
/
ただし、匿名ブロックでテストすると、 「正確なフェッチが要求された行数を超えて返されます」というエラーが表示されます
declare
v_sim number;
begin
v_sim:=func_similarity(1,4);
dbms_output.put_line(v_sim);
end;
/
これで、関数が理にかなっており、機能するはずだと確信しています(週末中ずっとかかりました)。なぜこれが機能しないのかについて、誰か考えがありますか?
前もって感謝します。