我有这2个错误,ORA-01422 ORA-06512

问题描述 投票:-1回答:1
declare 
    cm Pilote.comm%type;
    dt Pilote.embauche%type;
begin
    select comm, embauche into cm, dt from Pilote;
end;
oracle plsql oracle-sqldeveloper plsqldeveloper
1个回答
0
投票
太多行。您必须限制查询仅返回一行(例如,使用where子句),或者-如果您想选择更多行,则以不同的方式(例如,放入数组)。

例如:

SQL> set serveroutput on; SQL> SQL> declare 2 l_dname dept.dname%type; 3 l_loc dept.loc%type; 4 begin 5 select dname, loc 6 into l_dname, l_loc 7 from dept 8 where deptno = 10; 9 dbms_output.put_line(l_dname); 10 end; 11 / ACCOUNTING PL/SQL procedure successfully completed. SQL>

SQL> declare
  2    type l_dept is table of dept%rowtype;
  3    dept_arr l_dept;
  4  begin
  5    select deptno, dname, loc
  6      bulk collect into dept_arr
  7      from dept;
  8
  9    for i in dept_arr.first .. dept_arr.last loop
 10      dbms_output.put_line(dept_arr(i).dname);
 11    end loop;
 12  end;
 13  /
ACCOUNTING
RESEARCH
SALES
OPERATIONS

PL/SQL procedure successfully completed.

SQL>
© www.soinside.com 2019 - 2024. All rights reserved.