-2

此代码对我不起作用并给我发消息并发送消息

ORA-01422       exact fetch returns more than requested number of rows  

编码:

declare  
  a_id employees.employee_id%type;  
  b_name employees.first_name%type;  
  c_salary employees.salary%type;  
begin  
  for i in 1..10 loop  
    select employee_id, first_name, salary into a_id, b_name, c_salary from employees 
    where employee_id='a_id', first_name='b_name', salary='c_salary';  

    insert into awais(employee_id, first_name, salary) values (a_id, b_name, c_salary);  
  end loop;  
end;  
/
4

2 回答 2

2

看起来您的问题是您在a_id, b_name, c_salary.

您可以直接使用insert select

INSERT INTO awais
SELECT employee_id, first_name, salary into a_id, b_name, c_salary
  FROM employees 
 WHERE employee_id='a_id' 
   AND first_name='b_name' 
    AND salary='c_salary';

或者您可以使用光标进行循环:

declare  
  CURSOR c1
    IS
      select employee_id  a_id
           , first_name   b_name
           , salary       c_salary
        from employees 
       where employee_id='a_id' 
         AND first_name='b_name' 
         AND salary='c_salary'; 
begin  
  for i in 1..10 loop  
    for l_record in c1
    loop
      insert into awais(employee_id, first_name, salary) 
      values (l_record.a_id, l_record.b_name, l_record.c_salary); 
    end loop;


  end loop;  
end;  
/
于 2013-09-29T13:55:17.423 回答
0

IIUC,您可以采取更简单的方法:

INSERT INTO awais
(SELECT employee_id, first_name, salary into a_id, b_name, c_salary
 FROM   employees 
 WHERE employee_id='a_id' AND first_name='b_name' AND salary='c_salary');
于 2013-09-29T13:42:54.660 回答