3

私は、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;
/

これで、関数が理にかなっており、機能するはずだと確信しています(週末中ずっとかかりました)。なぜこれが機能しないのかについて、誰か考えがありますか?

前もって感謝します。

4

2 に答える 2

0

sim_value には 1 行のみを返す必要があります。何が起こっているかを確認するには、INTO を指定せずに IDS1 と IDS2 の値を使用して SQL を実行します。

于 2013-02-12T10:01:23.293 に答える