我有一個示例數據庫,我需要編寫一個存儲過程來打印給定的配方(其中包含的數據庫,包括成分和數量 - 所以我需要聯接表)PL SQL對象無效錯誤 - 無法找到源
CREATE OR REPLACE PROCEDURE proc_printrecipe (RecipeName IN Recipe.RecipeTitle%TYPE)
IS
TYPE rec_printrecipe IS RECORD
(
rec_IngName Ingredients.IngredientName%TYPE,
rec_Amount Recipe_Ingredients.Amount%TYPE,
rec_MeasureDesc Measurements.MeasurementDescription%TYPE,
)
CURSOR cur_printrecipe IS
SELECT i.ingredientName, ri.Amount, m.MeasurementDescription FROM Recipes r
JOIN Recipe_Ingredients ri ON r.RecipeID = ri.RecipeID
JOIN Ingredients i ON ri.IngredientID = i.IngredientID
JOIN Measurements m ON ri.MeasureAmountID = m.MeasurementDescription
WHERE r.RecipeTitle = RecipeName;
BEGIN
IF NOT cur_printrecipe%ISOPEN THEN
OPEN cur_printrecipe;
END IF;
LOOP
FETCH cur_printrecipe INTO rec_printrecipe;
EXIT WHEN cur_printrecipe%NOTFOUND;
dbms_output.put_line(rec_Amount || ' '
rec_MeasureDesc || ' of '
rec_IngName
);
END LOOP;
END;
/
-- CALLING THE STORED PROCEDURE
DECLARE
recipe recipes.RecipeTitle%TYPE := 'Irish Stew';
BEGIN
proc_printrecipe(recipe);
END;
但腳本輸出(帶的Oracle SQL Developer 1.1.3)工作給了我: 警告:執行與警告
PROCEDURE proc_printrecipe Compiled.
Error starting at line 33 in command:
DECLARE
recipe recipes.RecipeTitle%TYPE := 'Irish Stew';
BEGIN
proc_printrecipe(recipe);
END;
Error report:
ORA-06550: Line 4, Column 3:
PLS-00905: Object COOK.PROC_PRINTRECIPE is invalid
ORA-06550: Line 4, Column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
我缺少的是完成?
不要忘記在退出程序之前關閉打開的光標。否則,在將來的某個時刻,你的代碼會在內存不足的情況下將數據庫取出。 –