我想捕获并记录那些受影响的行另一个表

时间:2016-12-06 17:30:03

标签: oracle11g

我收到错误PL / SQL:ORA-00913:值太多了。 我想在这里做什么,我的更新语句影响多行。 我想要捕获并记录那些受影响的行另一个表。 请帮忙。 对于波纹管代码。

 DECLARE 
  TYPE cusRec IS TABLE OF customer%ROWTYPE INDEX BY PLS_INTEGER;
   v_cusRec  cusRec;

   BEGIN

    UPDATE customer
    SET l_optionalmail = 1
    WHERE c_customer_id IN (  SELECT c_customer_id
                          FROM     customer cus,
                                   agent age
                          WHERE cus.c_customer_id = age.c_customer_id
                          AND cus.l_optionalmail = 0
                          GROUP BY age.c_customer_id
                          HAVING MIN (age.d_movein) >=SYSDATE-1) 
      RETURNING cus.c_customer_id,cus.c_lastname,l_optionalmail
    BULK COLLECT INTO v_bif001Rec;
    DBMS_OUTPUT.PUT_LINE('Updated l_optionalmail column ' || SQL%ROWCOUNT || ' Rows.');
    FOR i IN v_bif001Rec.FIRST..v_bif001Rec.LAST LOOP

        INSERT INTO l_optionalmail_wrk(c_customer_id,c_lastname,l_optionalmail,d_created)
        VALUES (v_bif001Rec(i).c_customer_id,v_bif001Rec(i).c_lastname,v_bif001Rec(i).l_optionalmail,SYSDATE);
    END LOOP;
    END;

1 个答案:

答案 0 :(得分:0)

错误清楚地表明,您returning语句中update的列more比{vl} bif001Rec中定义的列record高。了解如何成功运行代码。我创建了一个table,然后创建了DECLARE TYPE cusRec IS TABLE OF employee%ROWTYPE INDEX BY PLS_INTEGER; v_cusRec cusRec; ---List down all the columns which you are returning from the update statement type emp_rec is record ( EMPLOYEE_ID NUMBER(5), FIRST_NAME VARCHAR2(20 CHAR), LAST_NAME VARCHAR2(20 CHAR) ); type v_bifRec is table of emp_rec index by pls_integer; v_bif001Rec v_bifRec; BEGIN UPDATE employee emp SET emp.dept_no = 10 WHERE emp.employee_id IN ( SELECT id_e from employees ) RETURNING emp.employee_id, emp.first_name, emp.last_name BULK COLLECT INTO v_bif001Rec; DBMS_OUTPUT.PUT_LINE ('Updated l_optionalmail column ' || SQL%ROWCOUNT || ' Rows.'); FOR i IN v_bif001Rec.FIRST .. v_bif001Rec.LAST LOOP --You can insert your records here. I Just displayed it. dbms_output.put_line('Employee_id= '||v_bif001Rec(i).EMPLOYEE_ID ||'Employee_First_name --'||v_bif001Rec(i).FIRST_NAME||'Employee Last_name--'||v_bif001Rec(i).LAST_NAME); /*INSERT INTO l_optionalmail_wrk (c_customer_id, c_lastname, l_optionalmail, d_created) VALUES (v_bif001Rec (i).c_customer_id, v_bif001Rec (i).c_lastname, v_bif001Rec (i).l_optionalmail, SYSDATE); */ END LOOP; END; 个记录,这些记录具有从update语句返回的相同列。

 url: '<%= Url.Action("CreateOrUpdateMember", "MailChimp") %>'