返还批量收款问题。代码出错

时间:2018-11-23 05:37:36

标签: plsql

执行以下代码时出错。无法找出问题? 似乎变量V1无法容纳太多的值

SQL> declare
  2  type T1 is table of employee%rowtype index by binary_integer;
  3  V1 T1;
  4  begin
  5  update employee set salary=salary+500
  6  where DESCRIPTION ='Tester'
  7  returning first_name,last_name,salary,description
  8  bulk collect into V1;
  9  dbms_output.put_line ('updated # of Tester are : ' ||sql%rowcount);
 10
 11  for i in V1.FIRST .. V1.LAST
 12  loop
 13  dbms_output.put_line (V1(i).first_name || ' ' ||
 14     V1(i).last_name  || ' ' ||
 15    V1(i).salary  || ' ' ||
 16           V1(i).description );
 17  end loop;
 18  end;
 19  /
bulk collect into V1;
                    *
ERROR at line 8:
ORA-06550: line 8, column 21:
PL/SQL: ORA-00913: too many values
ORA-06550: line 5, column 1:
PL/SQL: SQL Statement ignored

1 个答案:

答案 0 :(得分:0)

如果我们能按照您的建议去做,我会喜欢的。

您将返回4列,因此必须指定4个目标;不幸的是,这意味着您将需要4个数组,而不是单个记录数组。

declare
  type first_names_t is table of employee.first_name%type index by binary_integer;
  type last_names_t is table of employee.last_name%type index by binary_integer;
  type salaries_t is table of employee.salary%type index by binary_integer;
  type descriptions_t is table of employee.description%type index by binary_integer;
  first_names first_names_t;
  last_names last_names_t;
  salaries salaries_t;
  descriptions descriptions_t;
begin
  update employee set salary=salary+500
  where DESCRIPTION ='Tester'
  returning first_name,last_name,salary,description
  bulk collect into first_names,last_names,salaries,descriptions;
  ...