我想在更新表后将一些结果存储在临时表中但是它给了我一个包含多个条目的类别/书籍类型的错误。当我尝试使用具有一个条目的书籍类型时,一切正常。有人可以告诉我如何解决这个问题,我认为它与没有过滤器有关,尽管我不确定如何做到这一点。
DROP PROCEDURE UpdateAdvance;
CREATE OR REPLACE PROCEDURE UpdateAdvance (
p_BookType titles.category%TYPE,
p_NewAdvance advance_temptable.new_advance%TYPE) AS
CURSOR titles_cur IS
SELECT *
FROM titles
WHERE category=p_BookType
FOR UPDATE OF advance;
titles_rec titles_cur%ROWTYPE;
v_OldAdvance titles.advance%TYPE;
v_TitleID titles.title_id%TYPE;
v_Title titles.title%TYPE;
BEGIN
SELECT advance, title_id, title
INTO v_OldAdvance, v_TitleID, v_Title
FROM titles
WHERE category=p_BookType;
FOR titles_rec in titles_cur LOOP
INSERT INTO advance_temptable VALUES(advance_sequence.nextval, v_TitleID, v_Title, v_OldAdvance, p_NewAdvance);
END LOOP;
COMMIT;
END UpdateAdvance;
当我这样称呼它时
BEGIN
UpdateAdvance('psychology', 100);
END;
我收到错误:
Error starting at line : 35 in command -
BEGIN
UpdateAdvance('psychology', 100);
END;
Error report -
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SYSTEM.UPDATEADVANCE", line 14
ORA-06512: at line 2
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requested
应用解决方案,这就是我现在所做的工作。
DROP PROCEDURE UpdateAdvance;
CREATE OR REPLACE PROCEDURE UpdateAdvance (
p_BookType titles.category%TYPE,
p_NewAdvance advance_temptable.new_advance%TYPE) AS
BEGIN
INSERT INTO advance_temptable
select advance_sequence.nextval, title_id, title, advance, p_NewAdvance
FROM titles
WHERE category=p_BookType;
COMMIT;
END UpdateAdvance;
BEGIN
UpdateAdvance('psychology', 100);
END;
答案 0 :(得分:1)
你为什么不这样做:
INSERT INTO advance_temptable
select advance_sequence.nextval, TitleID, Title, Advance, p_NewAdvance
FROM titles
WHERE category = p_BookType;
没有光标?