2016-12-06 54 views
0

我得到一個錯誤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; 
+0

對我來說,它看起來像問題與v_bif001Rec。你能提供錯誤日誌嗎? – Rakesh

回答

0

這個錯誤清楚地說,從你update聲明你是returning列是more比你的集合中定義V_ bif001Rec列。瞭解如何成功運行代碼。我創建了一個record,然後是一個table的記錄與從update語句返回的同一列。

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; 
+0

是的,謝謝我解決了這個問題。再次感謝 – Sohel

+0

如果它解決了您的問題,您可以避開答案,以便讀者將來可以使用它。 – XING

相關問題