先建了一个表:
CREATE TABLE temp_table (
  num_col    NUMBER,
  char_col   VARCHAR2(60)
  );刚学pl/sql,照书上写了一个块,如下:
DECLARE
  2    v_Num1 number:=1;
  3    v_Num2 number:=2;
  4    v_String1 varchar2(60):='hello world!';
  5    v_String2 varchar2(60):='this message brought to you by pl/sql';
  6    v_OutputStr varchar2(60);
  7    begin
  8    insert into temp_table(num_col,char_col)
  9    values (v_Num1,v_String1);
 10    insert into temp_table(num_col,char_col)
 11    values(v_Num2,v_String2);
 12  
 13    select char_col
 14    into v_OutputStr
 15    from temp_table
 16    where num_col=v_Num1;
 17    dbms_output.put_line(v_OutputStr);
 18  
 19    select char_col
 20    into v_OutputStr
 21    from temp_table
 22    where num_col=v_Num2;
 23    dbms_Output.put_line(v_OutputStr);
 24    end;
 25  / 
但是执行完后就提示:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 13 都是看书写的居然有错,希望得到高手指点,修改好了马上结帖给分.

解决方案 »

  1.   

    select * from temp_table看看,是不是就那两条记录?
      

  2.   

    表中还存在其它的记录;
    这第7行后面加上一句
    7    begin
           delete temp_table;
      

  3.   

    insert之后没有commit,你没有设置为autocommit,select是取不到值的,在12行处加上commit;再试试
      

  4.   

    你多运行2次你的代码块,你会发觉记录数在增加的;
    运行代码块之前,delete temp_table;建议insert之后Commit;试试