簡體   English   中英

PL / SQL錯誤返回多行

[英]PL/SQL Error Return Multiple Rows

我想在更新表后將一些結果存儲在臨時表中,但是它給我一個關於具有多個條目的類別/書籍類型的錯誤。 當我嘗試使用具有一個條目的書本類型時,一切正常。 有人可以告訴我如何解決此問題,我認為這與沒有過濾器有關,盡管我不確定該怎么做。

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;

你為什么不這樣做:

INSERT INTO advance_temptable 
  select advance_sequence.nextval, TitleID, Title, Advance, p_NewAdvance
  FROM titles
  WHERE category = p_BookType;

沒有光標?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM