Plsql 为什么我会得到这个“答案”&引用;精确提取返回的行数超过请求的行数”;当我已经使用游标时?

Plsql 为什么我会得到这个“答案”&引用;精确提取返回的行数超过请求的行数”;当我已经使用游标时?,plsql,triggers,cursor,Plsql,Triggers,Cursor,我正在使用光标编写以下代码,以便光标可以拾取多行。但是,它仍然给我错误消息“精确获取返回的行数超过请求的行数”。不是光标一次只能检索一行数据。为什么这条信息还在显示 create or replace trigger e before delete on enrollment for each row declare get_tid scorest.tid%type; get_ferm scorest.ferm%type; g

我正在使用光标编写以下代码,以便光标可以拾取多行。但是,它仍然给我错误消息“精确获取返回的行数超过请求的行数”。不是光标一次只能检索一行数据。为什么这条信息还在显示

 create or replace trigger e
    before delete on enrollment
    for each row
    declare 
       get_tid scorest.tid%type;
       get_ferm scorest.ferm%type;
       get_sect scorest.sect%type;
       get_name scorest.name%type;
       get_score scorest.score%type;
       cursor findenrolls(atid in scorest.tid%type, 
                          aferm in scorest.ferm%type, 
                          asect in scorest.sect%type)
                          is select * from scorest;
    begin 
       for findenrolls_rec in findenrolls(:old.tid, :old.ferm, :old.sect) loop      
          select tid, ferm, sect, name, score
          into get_tid, get_ferm, get_sect, get_name, get_score
          from scorest
          where scorest.tid=:old.tid
          and scorest.ferm=:old.ferm
          and scorest.sect=:old.sect;

      insert into deleted_scores values (get_tid, get_ferm, get_sect, get_name, get_score);

      delete from scorest
      where tid=get_tid
      and ferm=get_ferm
      and sect=get_sect
      and name=get_name;
   end loop;
end;

您的错误来自此语句部分选择进入必须返回准确的一条记录

你必须重写你的代码使它工作。在不知道您的用例的情况下,它可能会更难,但您可以试试这个

CREATE OR REPLACE 
TRIGGER e before DELETE 
ON enrollment 
FOR EACH row 
BEGIN
    FOR get IN (
        SELECT tid
            , ferm
            , sect
            , name
            , score
            FROM scorest
            WHERE scorest.tid=:old.tid
            AND scorest.ferm =:old.ferm
            AND scorest.sect =:old.sect
    )
    LOOP
        INSERT
        INTO deleted_scores VALUES
            ( get.tid
            , get.ferm
            , get.sect
            , get.name
            , get.score
            );

        DELETE
        FROM scorest
        WHERE tid=get.tid
        AND ferm =get.ferm
        AND sect =get.sect
        AND name =get.name;
    END LOOP;
END;

如何看到显式光标消失并被隐式光标替换,这看起来更适合这种情况。

由于基于tid、ferm、sect的scorest表中存在重复数据,因此出现错误 你可以通过电话查一下

  select  tid , ferm ,sect from scorest having count(1)>1
  group by  tid , ferm ,sect;
如果可以在select语句中再添加一个条件,则不需要重复项

 select tid, ferm, sect, name, score
          into get_tid, get_ferm, get_sect, get_name, get_score
          from scorest
          where scorest.tid=:old.tid
          and scorest.ferm=:old.ferm
          and scorest.sect=:old.sect;
          and rownum =1
否则,您可以选择“Ftaveras”建议的方法

 select tid, ferm, sect, name, score
          into get_tid, get_ferm, get_sect, get_name, get_score
          from scorest
          where scorest.tid=:old.tid
          and scorest.ferm=:old.ferm
          and scorest.sect=:old.sect;
          and rownum =1