【发布时间】:2013-02-12 18:09:51
【问题描述】:
我一直在编写一个 PL/SQL 脚本来计算两个食谱之间的相似度。 Recipe 是包含所有标题、准备等的表格。Ingredient 是所有独特成分的存储位置,recipeing 是许多要很多问题都解决了,两者是联系在一起的。
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;
/
现在,我很确定这个功能是有意义的,并且 应该 工作(花了我整个周末)。有没有人知道为什么这可能不起作用?
提前致谢。
【问题讨论】:
-
你检查过查询它返回的amny行吗