LOOP inside FORALL in bulk binding

Can I use a loop inside forall in bulk bind updates?
as I understand, forall statement strictly loops through the length of the bulk limit size for the immediately following statement only.
I am attempting to use a loop there to update more than one table.
cursor c is select id from temp where dt_date > sysdate-30;
BEGIN
loop
fetch c into v_id;
limit 1000;
forall i in 1..v_id.count
UPDATE table_one set new_id = v_id(i);
exit when C%NOTFOUND;
end loop;
end;
I want to update another table table_two also immediately after updating table_one like this:
forall i in 1..v_id.count
UPDATE table_one set new_id = v_id(i);
BEGIN select nvl(code,'N/A') into v_code from T_CODES where ID_NO = v_id(i); EXCEPTION WHEN NO_DATA_FOUND v_code='N/A'; END;
UPDATE table_two set new_code =v_code;
exit when C% not found.
This is not working and when I run it, I get an error saying encountered BEGIN when one of the following is expected.
I got around this by having another FOR loop just to set up the values in another array variable and using that value in another second forall loop to update table_two.
Is there any way to do this multiple table udpates in bulkbinding under one forall loop that would enable to do some derivation/calculation if needed among variables [not array variables, regular datatype variables].
Can we have like
forall j in 1.. v_id.count
LOOP
update table 1;
derive values for updating table 2;
update table 2;
END LOOP;
Thank You.

Well, without questioning reasions why do you want this, you are confusing bulk select and forall. You need:
begin
    loop
      fetch c bulk collect into v_id limit 1000;
      exit when v_id.count = 0;
      forall i in 1..v_id.count
        UPDATE table_one set new_id = v_id(i);
    end loop;
end;
/SY.

Similar Messages

  • Explicit access of the index in bulk bind forall

    Hi
    I wonder if it is possible to access the index itself in a bulk bind. For instance:
    SQL> desc draft_responces;
    Name Type Nullable Default Comments
    S_NUMBER VARCHAR2(10)
    CLUSTER_ID NUMBER
    STATEMENT_ID NUMBER
    RESPONCE NUMBER Y
    RESP_NUM NUMBER Y
    and I wished to insert the responce number i into the resp_num:
    forall i in indices of p_statement_ids
    insert into draft_responces
    s_number
    ,cluster_id
    ,statement_id
    ,responce
    ,resp_num)
    values (
    p_snumber
    ,p_cluster_id
    ,p_statement_ids(i)
    ,p_responces(i)
    , i );
    which fails ... is it possible to access the index i in a bulk bind explicitly?
    thanks

    finophile wrote:
    Hi
    I wonder if it is possible to access the index itself in a bulk bind. For instance:
    SQL> desc draft_responces;
    Name Type Nullable Default Comments
    S_NUMBER VARCHAR2(10)
    CLUSTER_ID NUMBER
    STATEMENT_ID NUMBER
    RESPONCE NUMBER Y
    RESP_NUM NUMBER Y
    and I wished to insert the responce number i into the resp_num:
    forall i in indices of p_statement_ids
    insert into draft_responces
    s_number
    ,cluster_id
    ,statement_id
    ,responce
    ,resp_num)
    values (
    p_snumber
    ,p_cluster_id
    ,p_statement_ids(i)
    ,p_responces(i)
    , i );
    which fails ... is it possible to access the index i in a bulk bind explicitly?
    thanksHi,
    according to the documentation index is the "Name for the implicitly declared integer variable that is local to the FORALL statement. Statements outside the FORALL statement cannot reference index. Statements inside the FORALL statement can reference index as an index variable, *but cannot use it in expressions* or change its value. After the FORALL statement runs, index is undefined."
    So it appears the answer is no. You can get around this by using an ordinary for loop, though you don't get the benefit of bulk operations.
    Andre

  • Dynamic SQL and Bulk Bind... Interesting Problem !!!

    Hi Forum !!
    I've got a very interesting problem involving Dynamic SQL and Bulk Bind. I really Hope you guys have some suggestions for me...
    Table A contains a column named TX_FORMULA. There are many strings holding expressions like '.3 * 2 + 1.5' or '(3.4 + 2) / .3', all well formed numeric formulas. I want to calculate each formula, finding the number obtained as a result of each calculation.
    I wrote something like this:
    DECLARE
    TYPE T_FormulasNum IS TABLE OF A.TX_FORMULA%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE T_MontoIndicador IS TABLE OF A.MT_NUMBER%TYPE
    INDEX BY BINARY_INTEGER;
    V_FormulasNum T_FormulasNum;
    V_MontoIndicador T_MontoIndicador;
    BEGIN
    SELECT DISTINCT CD_INDICADOR,
    TX_FORMULA_NUMERICA
    BULK COLLECT INTO V_CodIndicador, V_FormulasNum
    FROM A;
    FORALL i IN V_FormulasNum.FIRST..V_FormulasNum.LAST
    EXECUTE IMMEDIATE
    'BEGIN
    :1 := TO_NUMBER(:2);
    END;'
    USING V_FormulasNum(i) RETURNING INTO V_MontoIndicador;
    END;
    But I'm getting the following messages:
    ORA-06550: line 22, column 43:
    PLS-00597: expression 'V_MONTOINDICADOR' in the INTO list is of wrong type
    ORA-06550: line 18, column 5:
    PL/SQL: Statement ignored
    ORA-06550: line 18, column 5:
    PLS-00435: DML statement without BULK In-BIND cannot be used inside FORALL
    Any Idea to solve this problem ?
    Thanks in Advance !!

    Hallo,
    many many errors...
    1. You can use FORALL only in DML operators, in your case you must use simple FOR LOOP.
    2. You can use bind variables only in DML- Statements. In other statements you have to use literals (hard parsing).
    3. RETURNING INTO - Clause in appropriate , use instead of OUT variable.
    4. Remark: FOR I IN FIRST..LAST is not fully correct: if you haven't results, you get EXCEPTION NO_DATA_FOUND. Use Instead of 1..tab.count
    This code works.
    DECLARE
    TYPE T_FormulasNum IS TABLE OF VARCHAR2(255)
    INDEX BY BINARY_INTEGER;
    TYPE T_MontoIndicador IS TABLE OF NUMBER
    INDEX BY BINARY_INTEGER;
    V_FormulasNum T_FormulasNum;
    V_MontoIndicador T_MontoIndicador;
    BEGIN
    SELECT DISTINCT CD_INDICATOR,
    TX_FORMULA_NUMERICA
    BULK COLLECT INTO V_MontoIndicador, V_FormulasNum
    FROM A;
    FOR i IN 1..V_FormulasNum.count
    LOOP
    EXECUTE IMMEDIATE
    'BEGIN
    :v_motto := TO_NUMBER('||v_formulasnum(i)||');
    END;'
    USING OUT V_MontoIndicador(i);
    dbms_output.put_line(v_montoindicador(i));
    END LOOP;
    END;You have to read more about bulk- binding and dynamic sql.
    HTH
    Regards
    Dmytro
    Test table
    a
    (cd_indicator number,
    tx_formula_numerica VARCHAR2(255))
    CD_INDICATOR TX_FORMULA_NUMERICA
    2 (5+5)*2
    1 2*3*4
    Message was edited by:
    Dmytro Dekhtyaryuk

  • Bulk Binding

    The below example is based on an example from Chapter 5 in Release 2 (9.2) documentation (Available in Oracle site).
    But it is failing and throwing the following error:
    "PLS-00435 DML statement without BULK In-BIND cannot be used inside FORALL".
    Can you pl suggest a workaround for this?
    CREATE TABLE test_ravi3 (col1 NUMBER, col2 VARCHAR2(20));
    CREATE TABLE test_ravi4 (col1 NUMBER, col2 VARCHAR2(20));
    INSERT INTO test_ravi3 VALUES(1,'RAVI' );
    INSERT INTO test_ravi3 VALUES(2,'RAVI1' );
    INSERT INTO test_ravi3 VALUES(3,'RAVI2' );
    INSERT INTO test_ravi3 VALUES(4,'RAVI3' );
    INSERT INTO test_ravi3 VALUES(5,'RAVI4' );
    DECLARE
    TYPE RecTabTyp IS TABLE OF test_ravi3%ROWTYPE
    INDEX BY BINARY_INTEGER;
    TYPE NumTabTyp IS TABLE OF NUMBER
    INDEX BY BINARY_INTEGER;
    TYPE CharTabTyp IS TABLE OF VARCHAR2(20)
    INDEX BY BINARY_INTEGER;
    CURSOR c1 IS SELECT col1, col2 FROM test_ravi4;
    rec_tab RecTabTyp;
    BEGIN
    SELECT COL1, COL2 BULK COLLECT INTO REC_TAB FROM TEST_RAVI3
    WHERE COL1 < 9;
    FORALL I IN REC_TAB.FIRST..REC_TAB.LAST
    INSERT INTO TEST_RAVI4 VALUES REC_TAB(I);
    FOR I IN REC_TAB.FIRST..REC_TAB.LAST LOOP
    REC_TAB(I).COL1 := REC_TAB(I).COL1 + 100;
    END LOOP;
    FORALL I IN REC_TAB.FIRST..REC_TAB.LAST
    UPDATE TEST_RAVI3 SET (COL1 ,COL2) = REC_TAB(I);
    OPEN C1;
    FETCH C1 BULK COLLECT INTO REC_TAB;
    CLOSE C1;
    END;

    Is block abc based on Table1? If it is, then you should NOT be issuing ANY update sql statements on the table. This just causes problems.
    Assuming abc is based on Table1, then the block should contain a text item for all three fields: Field1, col1, and col2. Then all you need is:
    Go_block('abc');
    first_record;
    Loop
      exit when :system.record_status='NEW';
      if :abc.field1 = 'Y' then
        :abc.col1 := value1;
      end if;
      exit when :system.last_record='TRUE';
    end loop;
    first_record;
    commit_form;
    Forms will take care of creating and executing the sql update statement, and it will do it using rowid, which is better than "where col2 = :abc.col2;" Also, you will no longer have locking problems.
    ...However... if abc is based on a table other than Table1, then something like your code is what you need to use. The fastest method of execution would be the bulk binding route, but do it from a package procedure on the database that you call from the form.

  • ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Truncated Bind

    Hi
    I am getting this run time error ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Truncated Bind in my pl/sql . I tried evrything , changing datatypes ,etc but still this error is coming .What can be the cause , please help.
    declare
    svid xxpor_utility.p_svid@sppmig1%type;
    p_sv_id xxpor_utility.p_svid@sppmig1%type;
    tab xxpor_utility.xxpor_indextab@sppmig1;
    svid1 xxpor_utility.p_svid@sppmig1%type;
    p_sv_id1 xxpor_utility.p_svid@sppmig1%type;
    tab1 xxpor_utility.xxpor_indextab@sppmig1;
    svid2 xxpor_utility.p_svid@sppmig1%type;
    p_sv_id2 xxpor_utility.p_svid@sppmig1%type;
    tab2 xxpor_utility.xxpor_indextab@sppmig1;
    svid3 xxpor_utility.p_svid@sppmig1%type;
    p_sv_id3 xxpor_utility.p_svid@sppmig1%type;
    tab3 xxpor_utility.xxpor_indextab@sppmig1;
    v_index t2_error_table.id_value%type;
    v_code t2_error_table.error_code%type;
    p_error varchar2(600);
    k number(20):=0;
    v_msg varchar2(2000);
    v_commit_count number(10);
    v_at_gpid varchar2(512);
    v_at_oper varchar2(512);
    v_sch varchar2(512);
    v_vat varchar2(512);
    exp exception;
    exp1 exception;
    exp2 exception;
    exp3 exception;
    exp4 exception;
    v_pay varchar2(512);
    v_res varchar2(512);
    v_digit varchar2(512);
    v_agree varchar2(512);
    v_driver_licence PERSON_HISTORY.drivers_licence%TYPE;
    v_cus_gen1 number(10);
    v_cus_gen2 number(10);
    v_cus_gen3 number(10);
    svid_sr number(10);
    v_social PERSON_HISTORY.social_security_number%TYPE;
    CURSOR person_cur (p_person_id person_history.person_id%TYPE)
    IS
    SELECT drivers_licence ,social_security_number
    FROM PERSON_HISTORY@SPPMIG1
    WHERE PERSON_ID=p_person_id --p2(p).person_id
         AND EFFECTIVE_START_DATE = (SELECT MAX(EFFECTIVE_START_DATE)
         FROM PERSON_HISTORY@sppmig1
                                            WHERE PERSON_ID=p_person_id);--p2(p).person_id) ;
    --p number(20):=1;
    --j number(20);
    cursor c1 is
    select * from cus_node_his ;
    type temp_c1 is table of customer_node_history%rowtype
    index by binary_integer;
    t2 temp_c1;
    type temp_c2 is table of customer_node_history@slpmig1%rowtype
    index by binary_integer;
    p2 temp_c2;
    /*cursor c2(p_id customer_query.customer_node_id%type) is
    select general_1,general_2,general_3
    from customer_query@sppmig1 c where c.customer_query_type_id=10003 and
    c.customer_node_id(+) =p_id
    and c.open_date = (select
    max(open_date) from customer_query@sppmig1 where customer_node_id=p_id
    and customer_query_type_id=10003 and c.customer_query_id =(select max(customer_query_id) from customer_query@sppmig1
    where customer_node_id=p_id and customer_query_type_id=10003));*/
    procedure do_bulk_insert is
    bulk_errors EXCEPTION;
    PRAGMA EXCEPTION_INIT(bulk_errors, -24381);
    begin
    forall j in 1..t2.count SAVE EXCEPTIONS
    insert into aaa values t2(j);
    commit;
    --t2.delete;
    k:=0;
    v_msg:=sqlerrm;
    EXCEPTION WHEN bulk_errors THEN
    FOR L IN 1..SQL%bulk_exceptions.count
    LOOP
    v_index := SQL%bulk_exceptions(L).ERROR_INDEX;
    v_code := sqlerrm(-1 * SQL%bulk_exceptions(L).ERROR_CODE);
    --v_index := SQL%bulk_exceptions(j).ERROR_INDEX;
    --v_code := sqlerrm(-1 * SQL%bulk_exceptions(j).ERROR_CODE);
    INSERT INTO t2_error_table
    VALUES('CUSTOMER_NODE_HISTORY',
    'CUSTOMER_NODE_ID',
    v_msg,
    t2(v_index).customer_node_id,
    null,
    'DO_BULK_INSERT',
    v_code
    commit;
    END LOOP;
    end do_bulk_insert;
    begin
    select value into v_at_gpid from t2_system_parameter@sppmig1 where name='atlanta_group_id';
    select value into v_commit_count from t2_system_parameter@sppmig1 where name='batch_size';
    select value into v_sch from t2_system_parameter@sppmig1 where name='schedule_id';
    select value into v_pay from t2_system_parameter@sppmig1 where name='payment_location_code';
    select value into v_at_oper from t2_system_parameter@sppmig1 where name='atlanta_operator_id';
    select value into v_digit from t2_system_parameter@sppmig1 where name='digits_to_be_screened';
    select value into v_res from t2_system_parameter@sppmig1 where name='responsible_agent';
    select value into v_vat from t2_system_parameter@sppmig1 where name='vat_rate';
    select value into v_agree from t2_system_parameter@sppmig1 where name='bank_agreement_status';
    xxpor_utility.xxpor_loadmemory@sppmig1('CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_TYPE_ID',tab);
    xxpor_utility.xxpor_loadmemory@sppmig1('CUSTOMER_NODE_HISTORY','CREDIT_RATING_CODE',tab2);
    xxpor_utility.xxpor_loadmemory@sppmig1('CUSTOMER_NODE_HISTORY','PAYMENT_METHOD_CODE',tab3);
    xxpor_utility.xxpor_loadmemory@sppmig1('CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_STATUS_CODE',tab1);
    open c1;
    loop
    fetch c1 bulk collect into p2 limit v_commit_count;
    for p in 1..p2.count loop
    k:=K+1;
    begin
    xxpor_utility.xxpor_getsvid@sppmig1(p2(p).CUSTOMER_NODE_TYPE_ID,tab,svid);
    p_sv_id:=svid;
    xxpor_utility.xxpor_getsvid@sppmig1(p2(p).CUSTOMER_NODE_STATUS_CODE,tab1,svid1);
    p_sv_id1 :=svid1;
    xxpor_utility.xxpor_getsvid@sppmig1(p2(p).CREDIT_RATING_CODE,tab2,svid2);
    p_sv_id2:=svid2;
    xxpor_utility.xxpor_getsvid@sppmig1(p2(p).PAYMENT_METHOD_CODE,tab3,svid3);
    p_sv_id3:=svid3;
    OPEN person_cur (p2(p).person_id);
    FETCH person_cur INTO v_driver_licence, v_social;
    CLOSE person_cur;
    --select social_security_number  into v_social from person_history@sppmig1 where
    --PERSON_ID=p2(p).person_id AND EFFECTIVE_START_DATE = (SELECT MAX(EFFECTIVE_START_DATE) FROM
    --PERSON_HISTORY@sppmig1 WHERE PERSON_ID=p2(p).person_id) ;
    /*open c2(p2(p).customer_node_id);
    fetch c2 into v_cus_gen1, v_cus_gen2, v_cus_gen3;
    close c2;
    xxpor_utility.get_status_code@sppmig1(v_cus_gen1,v_cus_gen2,v_cus_gen3,svid_sr);*/
    svid_sr:=2600000;
    t2(k).CUSTOMER_NODE_ID     :=     p2(p).CUSTOMER_NODE_ID;
    t2(k).LAST_MODIFIED          :=     p2(p).LAST_MODIFIED;
    t2(k).EFFECTIVE_START_DATE     :=     p2(p).EFFECTIVE_START_DATE;
    t2(k).EFFECTIVE_END_DATE     :=     p2(p).EFFECTIVE_END_DATE;
    t2(k).CUSTOMER_NODE_TYPE_ID     := p_sv_id;
    if p_sv_id is null then
    raise exp1;
    end if;
    t2(k).PRIMARY_IDENTIFIER      :=     p2(p).PRIMARY_IDENTIFIER;
    t2(k).PRIMARY_IDENTIFIER2     :=     p2(p).PRIMARY_IDENTIFIER2;
    t2(k).NODE_NAME           :=     p2(p).NODE_NAME ;
    t2(k).NODE_NAME_UPPERCASE     :=     p2(p).NODE_NAME_UPPERCASE ;
    t2(k).NODE_NAME_SOUNDEX     :=     p2(p).NODE_NAME_SOUNDEX;
    t2(k).ATLANTA_GROUP_ID          := v_at_gpid ;
    t2(k).ATLANTA_OPERATOR_ID     :=     p2(p).ATLANTA_OPERATOR_ID;
    t2(k).GL_CODE_ID          :=     p2(p).GL_CODE_ID;
    t2(k).PARENT_CUSTOMER_NODE_ID     := p2(p).PARENT_CUSTOMER_NODE_ID ;
    t2(k).HIERARCHY_LEVEL          := p2(p).HIERARCHY_LEVEL ;
    t2(k).ROOT_CUSTOMER_NODE_ID      := p2(p).ROOT_CUSTOMER_NODE_ID ;
    t2(k).CUSTOMER_NODE_STATUS_CODE := p_sv_id1 ;
    if p_sv_id1 is null then
    raise exp2;
    end if;
    t2(k).CREATED_DATE     :=          p2(p).CREATED_DATE;
    t2(k).ACTIVE_DATE      :=          p2(p).ACTIVE_DATE ;
    t2(k).PERSON_ID     :=          p2(p).PERSON_ID ;
    t2(k).PRIME_ACCOUNT_ID :=          p2(p).PRIME_ACCOUNT_ID;
    t2(k).REPORT_LEVEL_CODE :=          p2(p).REPORT_LEVEL_CODE;
    t2(k).POSTAL_ADDRESS_ID     :=     p2(p).POSTAL_ADDRESS_ID;
    t2(k).SITE_ADDRESS_ID     :=     p2(p).SITE_ADDRESS_ID ;
    t2(k).CURRENCY_ID      :=          p2(p).CURRENCY_ID;
    t2(k).SCHEDULE_ID     :=          v_sch;
    t2(k).BILLING_PRIORITY     :=     p2(p).BILLING_PRIORITY ;
    t2(k).BILLING_COMPLEXITY:=          p2(p).BILLING_COMPLEXITY ;
    t2(k).BILLING_CONFIGURATION_CODE     := p2(p).BILLING_CONFIGURATION_CODE;
    t2(k).SUPPRESS_IND_CODE           := p2(p).SUPPRESS_IND_CODE ;
    t2(k).SUPPRESS_BILL_CYCLE_COUNT := p2(p).SUPPRESS_BILL_CYCLE_COUNT;
    t2(k).SUPPRESS_UNTIL_ISSUE_DATE := p2(p).SUPPRESS_UNTIL_ISSUE_DATE;
    t2(k).TURNOVER               := p2(p).TURNOVER;
    t2(k).TURNOVER_CURRENCY_ID      :=     p2(p).TURNOVER_CURRENCY_ID ;
    t2(k).CREDIT_LIMIT           :=     p2(p).CREDIT_LIMIT ;
    t2(k).CREDIT_LIMIT_CURRENCY_ID :=     p2(p).CREDIT_LIMIT_CURRENCY_ID;
    t2(k).EXPECTED_REVENUE      :=     p2(p).EXPECTED_REVENUE ;
    t2(k).EXPECTED_REVENUE_CURRENCY_ID     := p2(p).EXPECTED_REVENUE_CURRENCY_ID ;
    t2(k).CREDIT_RATING_CODE      :=     p_sv_id2 ;
    -- if p_sv_id2 is null then
    --raise exp3;
    -- end if;
    t2(k).CREDIT_COMMENTS           := p2(p).CREDIT_COMMENTS ;
    t2(k).TAX_CLASS_CODE          := 1     ;
    t2(k).PAYMENT_METHOD_CODE     :=     p_sv_id3;
    --if p_sv_id3 is null then
    --raise exp4;
    --end if;
    t2(k).PAYMENT_LOCATION_CODE      := v_pay ;
    t2(k).BANK_CODE           :=     NULL;
    t2(k).BRANCH_CODE           :=     NULL ;
    t2(k).BANK_ACCOUNT_NAME     :=     p2(p).NODE_NAME ;
    t2(k).BANK_ACCOUNT_NUMBER     :=     '1000000';
    t2(k).BANK_ACCOUNT_REF      :=     v_agree;
    t2(k).CARD_TYPE_CODE          := p2(p).CARD_TYPE_CODE     ;
    t2(k).CARD_NUMBER          :=     p2(p).CARD_NUMBER ;
    t2(k).CARD_EXPIRY_DATE          := NULL ;
    t2(k).ASSIGNED_OPERATOR_ID      :=     NULL ;
    t2(k).SALES_CHANNEL_CODE     :=     0;
    t2(k).COMPANY_NUMBER          := NULL;
    t2(k).INDUSTRY_CODE          :=     NULL;
    t2(k).REGION_CODE           :=     NULL;
    t2(k).GENERAL_1          :=     v_vat ;
    t2(k).GENERAL_2           :=     svid_sr ;
    if svid_sr is null then
    raise exp;
    end if;
    t2(k).GENERAL_3           :=     v_social ;
    t2(k).GENERAL_4           :=     v_driver_licence ;
    t2(k).GENERAL_5           :=     v_vat;
    t2(k).GENERAL_6           :=     v_res;
    t2(k).GENERAL_7           :=     null||':'||null||':'||'1000000'||':'||null||':'||null||':'||null||':';
    t2(k).GENERAL_8          :=     '2' ;
    t2(k).GENERAL_9           :=     v_digit;
    t2(k).GENERAL_10          :=     p2(p).CUSTOMER_NODE_ID;
    exception when exp then
    p_error:= sqlerrm;
    insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
    ,null,null,null);
    commit;
    when exp1 then
    p_error:= sqlerrm;
    insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
    ,null,null,'customer_node_type_id is null');
    commit;
    when exp2 then
    p_error:= sqlerrm;
    insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
    ,null,null,'customer_node_status_code is null');
    commit;
    /*when exp3 then
    p_error:= sqlerrm;
    insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
    ,null,null,'credit_rating_code is null');
    commit;
    when exp4 then
    p_error:= sqlerrm;
    insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
    ,null,null,null);
    commit;*/
    when others then
    p_error:= sqlerrm;
    insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,p2(p).customer_node_id
    ,null,null,null);
    commit;
    end;
    if mod(k,v_commit_count)=0 then
    do_bulk_insert;
    t2.delete;
    end if;
    end loop;
    do_bulk_insert;
    exit when c1%notfound;
    end loop;
    t2.delete;
    exception when others then
    p_error:= sqlerrm;
    insert into t2_error_table values ( 'CUSTOMER_NODE_HISTORY','CUSTOMER_NODE_ID',p_error,null
    ,null,null,null);
    commit;
    RAISE;
    end;
    /

    Hi there,
    Following is the description of the error, you are getting.
    ORA-06502:VALUE_ERROR
    An arithmetic, conversion, truncation, or size-constraint error occurs. For example, when your program selects a column value into a character variable, if the value is longer than the declared length of the variable, PL/SQL aborts the assignment and raises VALUE_ERROR. In procedural statements, VALUE_ERROR is raised if the conversion of a character string into a number fails. (In SQL statements, INVALID_NUMBER is raised.)
    Hopefully this will help.

  • Bulk binding in 11g

    Hello,
    My below block works perfectly fine. However the processing takes longer time because of the volume of
    records in the table. I would like to change this below code to use FORALL.
    How can I convert the code to use bulk binding FORALL instead of 'For'.
    Declare
    Cursor  C1 Is Select
    a.old_transaction_id from
    Ideaal_Cons.Tb_Prchs_Sale_Trans_Base A
    where Rownum < 10;
    Type C_Typ Is Table Of C1%Rowtype Index By Pls_Integer;
    C_Rectype C_Typ;
    Type Tab_Desc Is Table Of Ideaal_Cons.Tb_Bookkeeping_Trans_Base.Desc_Line1%Type;
    Type Tab_Nbr Is Table Of Number;
      V_Desc_Tab Tab_Desc;
      V_Nbr      Tab_Nbr; 
      V_Desc_Line1 Varchar2(50);
      V_Desc_Line2 Varchar2(50);
      V_Desc_Line3 Varchar2(50);
      V_Desc_Line4 Varchar2(50);
      V_Desc_Line5 Varchar2(50);
      V_Desc_Line6 Varchar2(50);
      V_Desc_Line7 Varchar2(50);
      V_Desc_Line8 Varchar2(50);
      a number;
      V_Rec Number :=0;
      V_User Varchar2(20) := 'Sisadmin';
    Begin
       Dbms_Output.Enable;
       Open C1;
       Loop
       Fetch C1 Bulk Collect Into C_Rectype Limit 500;
        if C_Rectype.COUNT > 0 THEN
           FOR i IN C_Rectype.FIRST..C_Rectype.LAST
           loop
         Select Line_No,
                Desc_Line
          Bulk Collect Into
              V_Nbr, V_Desc_Tab
          From Ideaal_Staging.Tb_Sisadmin_Trade_Descr
          Where Transaction_Id = C_Rectype(I).Old_Transaction_Id
             Union All
             Select Null As Line_No, Null As Desc_Line From Dual
          Union All
          Select Null As Line_No, Null As Desc_Line From Dual
          Union All
          Select Null As Line_No, Null As Desc_Line From Dual
          Union All
          Select Null As Line_No, Null As Desc_Line From Dual
          Union All
          Select Null As Line_No, Null As Desc_Line From Dual
          Union All
          Select Null As Line_No, Null As Desc_Line From Dual
          Union All
          Select Null As Line_No, Null As Desc_Line From Dual
          Union All
          Select Null As Line_No, Null As Desc_Line From Dual
          Order By Line_No Asc
              V_Desc_Line1 := V_Desc_Tab(1);
              V_Desc_Line2 := V_Desc_Tab(2);
              V_Desc_Line3 := V_Desc_Tab(3);
              V_Desc_Line4 := V_Desc_Tab(4);
              V_Desc_Line5 := V_Desc_Tab(5);
              V_Desc_Line6 := V_Desc_Tab(6);
              V_Desc_Line7 := V_Desc_Tab(7);
              V_Desc_Line8 := V_Desc_Tab(8);
         Update Ideaal_Cons.Tb_Prchs_Sale_Trans_Base
            Set
              Desc_Line1  = V_Desc_Line1,
              Desc_Line2  = V_Desc_Line2,          
              Desc_Line3  = V_Desc_Line3,          
              Desc_Line4  = V_Desc_Line4,          
              Desc_Line5  = V_Desc_Line5,          
              Desc_Line6  = V_Desc_Line6,          
              Desc_Line7  = V_Desc_Line7,          
              Desc_Line8  = V_Desc_Line8
         Where Old_Transaction_Id = C_Rectype(I).Old_Transaction_Id;
         end loop;
       END IF;
         V_Rec := V_Rec + Nvl(C_Rectype.Count,0);
            Commit;
        Exit When C_Rectype.Count = 0;
    End Loop;
    Dbms_Output.Put_Line('Total Rec updated To Trade Table :- '|| V_Rec);
    End;
    /

    Cool stuff, so you should be able to read through that link and implement the update in that manner if you have issues running the single update command.
    As best i can tell, this works for your needs ... again, i don't know your data so you may have to muddle with it a bit. If you need help with that you will have to start showing your data and explaining "why" or "how" it doesn't fit your requirement.
    TUBBY_TUBBZ?drop table Tb_Prchs_Sale_Trans_Base;
    Table dropped.
    Elapsed: 00:00:00.06
    TUBBY_TUBBZ?drop table Tb_Sisadmin_Trade_Descr;
    Table dropped.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?
    TUBBY_TUBBZ?create table Tb_Prchs_Sale_Trans_Base
      2  (
      3     Transaction_Id       number,
      4     Old_Transaction_Id   number,
      5     desc_line1           varchar2(10),
      6     desc_line2           varchar2(10),
      7     desc_line3           varchar2(10),
      8     desc_line4           varchar2(10),
      9     desc_line5           varchar2(10),
    10     desc_line6           varchar2(10),
    11     desc_line7           varchar2(10),
    12     desc_line8           varchar2(10)
    13  );
    Table created.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?
    TUBBY_TUBBZ?insert into Tb_Prchs_Sale_Trans_Base (Transaction_Id, Old_Transaction_Id) values (998, 1);
    1 row created.
    Elapsed: 00:00:00.00
    TUBBY_TUBBZ?insert into Tb_Prchs_Sale_Trans_Base (Transaction_Id, Old_Transaction_Id) values (999, 2);
    1 row created.
    Elapsed: 00:00:00.00
    TUBBY_TUBBZ?
    TUBBY_TUBBZ?
    TUBBY_TUBBZ?create table Tb_Sisadmin_Trade_Descr
      2  (
      3     Transaction_Id number,
      4     line_nbr       number,
      5     desc_line      varchar2(10)
      6  );
    Table created.
    Elapsed: 00:00:00.00
    TUBBY_TUBBZ?
    TUBBY_TUBBZ?insert into Tb_Sisadmin_Trade_Descr values (1, 1, 'line1');
    1 row created.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?insert into Tb_Sisadmin_Trade_Descr values (1, 2, 'line2');
    1 row created.
    Elapsed: 00:00:00.00
    TUBBY_TUBBZ?insert into Tb_Sisadmin_Trade_Descr values (1, 3, 'line3');
    1 row created.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?
    TUBBY_TUBBZ?insert into Tb_Sisadmin_Trade_Descr values (2, 4, 'line4');
    1 row created.
    Elapsed: 00:00:00.00
    TUBBY_TUBBZ?insert into Tb_Sisadmin_Trade_Descr values (2, 5, 'line5');
    1 row created.
    Elapsed: 00:00:00.00
    TUBBY_TUBBZ?
    TUBBY_TUBBZ?
    TUBBY_TUBBZ?update Tb_Prchs_Sale_Trans_Base tgt
      2     set
      3        (desc_line1, desc_line2, desc_line3, desc_line4, desc_line5, desc_line6, desc_line7, desc_line8)
      4     =
      5     (
      6        select
      7           max(decode(line_nbr, 1, desc_line)),
      8           max(decode(line_nbr, 2, desc_line)),
      9           max(decode(line_nbr, 3, desc_line)),
    10           max(decode(line_nbr, 4, desc_line)),
    11           max(decode(line_nbr, 5, desc_line)),
    12           max(decode(line_nbr, 6, desc_line)),
    13           max(decode(line_nbr, 7, desc_line)),
    14           max(decode(line_nbr, 8, desc_line))
    15        from
    16           Tb_Sisadmin_Trade_Descr src
    17        where
    18           src.Transaction_Id   = tgt.Old_Transaction_Id
    19     );
    2 rows updated.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?select * from Tb_Prchs_Sale_Trans_Base;
        TRANSACTION_ID OLD_TRANSACTION_ID DESC_LINE1                     DESC_LINE2                     DESC_LINE3                     DESC_LINE4                     DESC_LINE5                     DESC_LINE6                     DESC_LINE7                     DESC_LINE8
                   998                  1 line1                          line2                          line3
                   999                  2                                                                                              line4                          line5
    2 rows selected.
    Elapsed: 00:00:00.00
    TUBBY_TUBBZ?

  • Error  in  bulk bind

    Hi  All,
    i am  new  for bulk binding  when i am trying  to insert  data  in  table  getting  error  PL/SQL: ORA-00904: : invalid identifier
    i need  to insert  data  in  to one  column below  are  the  desc for the  same .
    OR REPLACE function OMDV4_IDENTITY_OWNER.testing2(enterno in    number ) return number
    TYPE t_tab IS TABLE OF emp.empno%TYPE;
    := t_tab();
    NUMBER; 
    EXCEPTION;
    PRAGMA EXCEPTION_INIT(ex_dml_errors, -01400);
    -- Fill the collection.
    FOR i IN 1 .. 5 LOOP
    .extend;
    (l_tab.last):= i;
    END LOOP;
    delete from emp;
    commit;
    -- Perform a bulk operation.
    BEGIN
    FORALL i IN l_tab.first .. l_tab.last
    INSERT INTO EMP
    VALUES l_tab(i); ------ here  i am  getting  error
    EXCEPTION
    WHEN ex_dml_errors THEN
    := SQL%BULK_EXCEPTIONS.count;
    ('Number of failures: ' || l_error_count);
    FOR i IN 1 .. l_error_count LOOP
    ('Error: ' || i ||
    ' Array Index: ' || SQL%BULK_EXCEPTIONS(i).error_index ||
    ' Message: ' || SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
    END LOOP;
    END;
    return 1;
    END;
    Thanks

    I hope that you are just practicing BULK COLLECT. Because what you are doing using bulk collect is completely unnecessary. This can be simply done in SQL.
    What is your DB version. Referring record type directly in value clause is available from 11g onwards I guess. In previous version you get the following error.
    PL/SQL: ORA-03001: unimplemented feature
    So to fix your problem your FORALL code should be like this
    forall i in l_tab.first .. l_tab.last
       insert into emp_t (empno) values (l_tab(i));
    That's because l_tab contains the value of EMPNO alone. so you need to specify the column name in your insert statement. Also you need to use Brackets before and after l_tab(i).

  • Accessing the index in bulk binds

    Hi
    I wonder if it is possible to access the index itself in a bulk bind. For instance:
    SQL> desc draft_responces;
    Name Type Nullable Default Comments
    S_NUMBER VARCHAR2(10)
    CLUSTER_ID NUMBER
    STATEMENT_ID NUMBER
    RESPONCE NUMBER Y
    RESP_NUM NUMBER Y
    and I wished to insert the responce number i into the resp_num:
    forall i in indices of p_statement_ids
    insert into draft_responces
    s_number
    ,cluster_id
    ,statement_id
    ,responce
    ,resp_num)
    values (
    p_snumber
    ,p_cluster_id
    ,p_statement_ids(i)
    ,p_responces(i)
    , i );
    which fails ... is it possible to access the index i in a bulk bind explicitly?
    thanks

    You're in the wrong forum (this one is for issues with the SQL Developer tool). You'll get more answers in the SQL And PL/SQL forum.
    Have fun,
    K.

  • No performance improvement with  Bulk Binding

    Hi All,
    I need to update 0.2 million rows in (t_shdr_trx_stg ), previously it was... FOR loop..I converted it to bulk binding... but i can can hadrly see any improvement....
    Any clue I am missing something...please check my code snippet
    Cursor
    M I missing something
    Edited by: user8650395 on Nov 28, 2009 6:00 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Just a blind Shot
    FETCH  cur_tsts BULK COLLECT INTO v_cur_tsts LIMIT 1000; /*changed 400000 to 1000*/
    --PLease try thisThese Links will tell you my reasoning for that above suggestion
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:177628700346350496
    and
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1583402705463
    and
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:5918938803188
    Cheers!!!
    Bhushan
    Edited by: Buga --Added Links                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Question regarding bulk binding

    Gurus,
    How does oracle try to differentiate whether the query should use the concept of bulk binding and a normal query ? Is the key word FOR ALL makes the difference ? Or is there any other difference ??
    Please help
    Regards

    Its not up to oracle to decide, Its the developer who decides it. Bulk bind is used to reduce context switch. And you can achieve it with some of the bulk bind utilities provided by oracle like FORALL and BULK COLLECT.
    Read [Overview of Bulk Binds|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_packages.htm#sthref853] for more info.
    Thanks,
    Karthick.

  • Making .mov to loop inside flash

    I have a seamless quicktime .mov of clouds I want to use as a background.
    I set my flash animation to loop...but at the end of the .mov file instead of looping it just quits.
    How do I get the quicktime .mov file to loop within flash?
    Using Flash CS4

    Re: Loop inside a loop making performance poor!!!Yup, it probably will be.
    Your nested loops have an advantage in that they give you control over the process of what is happening. Unfortunately due to several factors including context switching between pl/sql and the sql engine this process is all but certain to be slower than doing the work in SQL.
    Instead of nested loops which call a procedure define a cursor directly your routine to get the data, then use a bulk collect - you can read about them in the documentation - to load your collection. One select with a bulk collect is all but certain to be faster than loading each row one item at a time.

  • Jdbc thin driver bulk binding slow insertion performance problem

    Hello All,
    We have a third party application reporting slow insertion performance, while I traced the session and found out most of elapsed time for one insert execution is sql*net more data from client, it appears bulk binding is being used here because one execution has 200 rows inserted. I am wondering whether this has something to do with their jdbc thin driver(10.1.0.2 version) and our database version 9205. Do you have any similar experience on this, what other possible directions should I explore?
    here is the trace report from 10046 event, I hide table name for privacy reason.
    Besides, I tested bulk binding in PL/SQL to insert 200 rows in one execution, no problem at all. Network folks confirm that network should not be an issue as well, ping time from app server to db server is sub milisecond and they are in the same data center.
    INSERT INTO ...
    values
    (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17,
    :18, :19, :20, :21, :22, :23, :24, :25, :26, :27, :28, :29, :30, :31, :32,
    :33, :34, :35, :36, :37, :38, :39, :40, :41, :42, :43, :44, :45)
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.02 14.29 1 94 2565 200
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.02 14.29 1 94 2565 200
    Misses in library cache during parse: 1
    Optimizer goal: CHOOSE
    Parsing user id: 25
    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    ---------------------------------------- Waited ---------- ------------
    SQL*Net more data from client 28 6.38 14.19
    db file sequential read 1 0.02 0.02
    SQL*Net message to client 1 0.00 0.00
    SQL*Net message from client 1 0.00 0.00
    ********************************************************************************

    I have exactly the same problem, I tried to find out what is going on, changed several JDBC Drivers on AIX, but no hope, I also have ran the process on my laptop which produced a better and faster performance.
    Therefore I made a special solution ( not practical) by creating flat files and defining the data as an external table, the oracle will read the data in those files as they were data inside a table, this gave me very fast insertion into the database, but still I am looking for an answer for your question here. Using Oracle on AIX machine is a normal business process followed by a lot of companies and there must be a solution for this.

  • Jdbc thin driver and bulk binding slow insertion performance

    Hello All,
    We have a third party application reporting slow insertion performance, while I traced the session and found out most of elapsed time for one insert execution is sql*net more data from client, it appears bulk binding is being used here because one execution has 200 rows inserted. I am wondering whether this has something to do with their jdbc thin driver(10.1.0.2 version) and our database version 9205. Do you have any similar experience on this, what other possible directions should I explore?
    here is the trace report from 10046 event, I hide table name for privacy reason.
    Besides, I tested bulk binding in PL/SQL to insert 200 rows in one execution, no problem at all. Network folks confirm that network should not be an issue as well, ping time from app server to db server is sub milisecond and they are in the same data center.
    INSERT INTO ...
    values
    (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17,
    :18, :19, :20, :21, :22, :23, :24, :25, :26, :27, :28, :29, :30, :31, :32,
    :33, :34, :35, :36, :37, :38, :39, :40, :41, :42, :43, :44, :45)
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.02 14.29 1 94 2565 200
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.02 14.29 1 94 2565 200
    Misses in library cache during parse: 1
    Optimizer goal: CHOOSE
    Parsing user id: 25
    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    ---------------------------------------- Waited ---------- ------------
    SQL*Net more data from client 28 6.38 14.19
    db file sequential read 1 0.02 0.02
    SQL*Net message to client 1 0.00 0.00
    SQL*Net message from client 1 0.00 0.00
    ********************************************************************************

    I have exactly the same problem, I tried to find out what is going on, changed several JDBC Drivers on AIX, but no hope, I also have ran the process on my laptop which produced a better and faster performance.
    Therefore I made a special solution ( not practical) by creating flat files and defining the data as an external table, the oracle will read the data in those files as they were data inside a table, this gave me very fast insertion into the database, but still I am looking for an answer for your question here. Using Oracle on AIX machine is a normal business process followed by a lot of companies and there must be a solution for this.

  • Smart form - loop inside a loop

    Dear Techies,
      I am new to smartforms. I have a query, in one of the code examples there is a context menu on the main window called "complex selection", but i dont find the same in my editor, what is the reason.
      I want this because i have data in two internal tables. Different tables are generated from secondary depending on the entries in first table. how do i achieve this on the main window.
    Similar to loop inside a loop, depending on my first table entries, all the entries belonging to that entry are to be put in table of second entry. i will have tables equal to the entries in first internal table. hope my question is clear.
    Please help.
    Regards
    imran.

    Hye..
      Loop in main area will fill only the current table, but i want several tables depending on entries in the first internal table.  The number of tables in the main window will be the number records in the first table.
    Regards
    imran.

  • I have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    i have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    Hi fais,
    Following through with what JB suggested. The steps involved in replacing the inner for loop with a while loop are outlined below.
    You can replace the inner for loop with a while by doing the following.
    1) Right-click of the for loop and select "Repalce" then navigate to the "while loop".
    2) Make sure the tunnels you where indexing on with the for loop are still indexing.
    3) Drop an "array size" node on your diagram. Wire the array that determines the number of iterations your for loop executes into this "array size".
    4) Wire the output of the array size into the new while loop.
    5) Set the condition terminal to "stop if true".
    6)Drop an "OR" gate inside the while loop and wire its output to the while loops condition terminal.
    7) C
    reate a local of the boolean "stop" button, and wire it into one of the inputs of your OR gate. This will allow you to stop the inner loop.
    8) Drop a "less than" node inside the inner while loop.
    9) Wire your iteration count into the bottom input of the "less than".
    10) Wire the count (see step 4 above) into the top input of the less than. This will stop the inner loop when ever the inner loop has processed the last element of your array.
    Provided I have not mixed up my tops and bottoms this should accomplish the replacement.
    I will let others explain how to takle this task using the "case solution".
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

Maybe you are looking for

  • Why do I keep getting, this mp4 "was not copied to your ipod because it cannot be played on this ipod"?

    Why do I keep getting, this mp4 "was not copied to your ipod because it cannot be played on this ipod"?

  • Powerbook  G4 from 10.4.11 to 10.5.8

    I have a Powerbook G4 that I want to use my iphone3Gs on. But after the new upgrade for iphone I can't use it on the Powerbook only my Windows. My iTunes is 9.2.1 When I tried to use it, it said I need 10.5.8. I have the upgrade but when I tried to i

  • Printing a Customer Receivables Aging Report Doesn't Include PO #

    The standard Detailed Receivables Aging report uses variable 152 that is supposed to show the Cust/Vendor Ref No.  It doesn't show anything however.  I tried changing it to a database field and relating it to the document #, but that didn't pull in a

  • Configuration error: 16

    I recieve this configuration error each time i exit and reopen adobe indesign.Than to fix it, i have to uninstall and reinstall the product. I even tried Adobe cleaner tool, still didnt work! Any idea on how to fix this issue permanantly?

  • PDF Printing in APEX 3.0

    Hello. I am working my way thru the PDF Printing in Application Express 3.0 document. I am currently stuck at step 5: Configure Oracle Application Express to use the JSP for PDF printing. When I access the Admin Services home page and select Manage S