2 MERGE statements in same trigger - is it possible ?

Hi guys,
I have an After Insert trigger (on table A) that takes the last record from table A and insert/update it on another table (B) then insert /update in same table (B) some records which depends on it. When trying to insert data in table A, the trigger raise this error: ORA-04092: cannot COMMIT in a trigger.
I understand the error, but I need expert's opinion to make the trigger works.
Here is the actual situation:
Table A has a trigger on after insert, and BASED ON THE LAST ROW inserted (only this data is subject to the trigger's actions) does the following:
1. MERGE the data (last row from the source table=A) with the data from the table destination=B. This data is specific to an employee;
2. Open a cursor that goes through all the ancestors of the employee (I have an employees hierarchy) and MERGE the same data (but for ancestors) with the table destination;
To be more specific :
EmpID LOB Day Status
12 1007 29 Solved
EmpID has ancestors 24 and 95. Therefore in the destination table I will have to do:
1. Merge data for EmpID 12;
2. Merge data for EmpID 24, 95:
EmpID LOB Day Status
24 1007 29 Just S (this is the status for ancestors)
95 1007 29 Just S
Steps 1 and 2 are inside a PL/SQL procedure that works fine by itself, but not within the trigger (since there are many transactions on the destination table). These 2 steps are required because for EmpID 12 I set a status and for the ancestors I set up a different status (this was the only way I could think of).
Can someone give me a hint how should I handle this situation ?
Thank you,
John

Based on my understanding of what you are trying to do you are going about this in the wrong way. Try this approach instead:
1. Trigger fires initiating the process and passes relevant :NEW values to a stored procedure
2. The stored procedure does all the work and possibly should be an autonomous transaction
It looks very much like your code just doesn't belong in a trigger.
PS: Why a MERGE statement? If the rows most likely do not exist then INSERT and UPDATE in your exception handler: Otherwise UPDATE as the default and INSERT in the exception handler. It is not very likely the percentage of inserts and updates will be near 50% each.

Similar Messages

  • Looping thru merge statement

    I have a merge statement, this executes for all the rows when the procedure is executed. Here i would like to include this merge statement as the part of LOOP so that all records will not get updated for a one time.
    how can i change this merge statement to include as the part of LOOP here.
    the user id should be the key to update the table USERS in merge statement, the same user id is exists in the bulk collect too..
    BEGIN
    v_sysdate:= pkg_utilities.fn_sysdate(1) ;
    o_Error_Text := 'ORA-Error in updating end date in user_status table ';
    tname:= 'user_status';
         MERGE INTO user_status r1
         USING (
              SELECT rowid rid , lead(start_period) OVER (PARTITION by user_id
              order by start_period)- 1 new_enddate FROM user_status ) r2
         ON ( r1.rowid = r2.rid )
         WHEN MATCHED THEN
         UPDATE SET end_period = new_enddate ;
         OPEN generic_cv4
         FOR SELECT
         user_id,user_status_type_id
         FROM user_status
         WHERE end_period IS NULL;
    LOOP
    FETCH generic_cv4 BULK COLLECT INTO
    v_user_id_seq,
    v_user_status_new
    LIMIT p_array_size;
    EXIT WHEN v_user_id_seq.COUNT = 0;
    IF v_user_id_seq.COUNT > 0 THEN
         o_Error_Text := 'ORA-Error in update user_status type id in users table ';
         tname:= 'users';
    FORALL I IN v_user_id_seq.FIRST..v_user_id_seq.LAST
    UPDATE users
    SET user_status_type_id = v_user_status_new(i),
    last_upd_date = v_sysdate
    WHERE user_id = v_user_id_seq(i);
    END IF;
    COMMIT;
    END LOOP;
    v_user_id_seq.delete;
    v_user_status_new.delete;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Error' ||sqlerrm);
    DBMS_OUTPUT.PUT_LINE(o_Error_Text);
    v_sql_err :=SQLERRM;
    ROLLBACK;
    pkg_champ_message_log.champ_message_log ('PKG_MIGRATE_V1_NESTED_MEMBER.p_update_member_status', tname, null,'Nested', v_sql_err,'Error',o_Error_Text,O_STATUS);
    END;

    Now lets talk how can i keep this merge statemnet as the part of the loop. It seems your mind is made up.
    Unfortunately, what you're asking makes no sense at all. You can't "loop through a merge statement".
    If you don't want to use merge for the entire table at once, the only thing you can do is to break up the table in your USING clause by some sort of range (maybe an account number or whatever). You could then run your code for each range (or even run them in parallel).
    The only other option is to not use MERGE at all and duplicate the logic of it within your loop (which is what I said in my first response).

  • Instead of trigger is NOT firing for merge statements in Oracle 10gR2

    The trigger fires fine for a update statement, but not when I use a merge statement
    with an update clause. Instead I get the normal error for the view ( which is a union all view, and therefore not updatable.)
    The error is :-
    ORA-01733: virtual column not allowed here
    oracle release is 10.2.0.2 for AIX 64L
    Is this a known bug ?
    I've used a multi-table insert statement to work around the problem for inserts, but
    for updates, I'd really like to be able to use a merge statement instead of an update.
    Mark.

    This is my cut-down version :-
    In this case case I'm getting an :-
    ORA-01446: cannot select ROWID from, or sample, a view with DISTINCT, GROUP BY, etc.
    rather then the ora-01733 error I get in the real code ( which is an update from an involved
    XML expression - cast to a table form)
    create table a ( a int primary key , b char(30) ) ;
    create table b ( a int primary key , b char(30) ) ;
    create view vw_a as
    select *
    from a
    union all
    select *
    from b ;
    ALTER VIEW vw_a ADD (
    PRIMARY KEY
    (a) DISABLE);
    DROP TRIGGER TRG_IO_U_ALL_AB;
    CREATE OR REPLACE trigger TRG_IO_U_ALL_AB
    instead of update ON vw_a
    for each row
    begin
    update a targ
    set b = :new.b
    where targ.a = :new.a
    if SQL%ROWCOUNT = 0
    then
         update b targ
         set b      = :new.b
         where targ.a = :new.a
    end if ;
    end ;
    insert into a values (1,'one');
    insert into a values (2,'two');
    insert into a values (3,'three');
    insert into b values (4,'quatre');
    insert into b values (5,'cinq');
    insert into b values (6,'six');
    commit;
    create table c as select a + 3 as a, b from a ;
    commit;
    merge into vw_a targ
    using (select * from c ) src
    on ( targ.a = src.a )
    when matched
    then update
    set targ.b = src. b
    select * from vw_a ;
    rollback ;
    update vw_a b
    set b = ( select c.b from c where b.a = c.a )
    where exists ( select c.b from c where b.a = c.a ) ;
    select * from vw_a ;
    rollback ;

  • Issue while using SUBPARTITION clause in the MERGE statement in PLSQL Code

    Hello All,
    I am using the below code to update specific sub-partition data using oracle merge statements.
    I am getting the sub-partition name and passing this as a string to the sub-partition clause.
    The Merge statement is failing stating that the specified sub-partition does not exist. But the sub-partition do exists for the table.
    We are using Oracle 11gr2 database.
    Below is the code which I am using to populate the data.
    declare
    ln_min_batchkey PLS_INTEGER;
    ln_max_batchkey PLS_INTEGER;
    lv_partition_name VARCHAR2 (32767);
    lv_subpartition_name VARCHAR2 (32767);
    begin
    FOR m1 IN ( SELECT (year_val + 1) AS year_val, year_val AS orig_year_val
    FROM ( SELECT DISTINCT
    TO_CHAR (batch_create_dt, 'YYYY') year_val
    FROM stores_comm_mob_sub_temp
    ORDER BY 1)
    ORDER BY year_val)
    LOOP
    lv_partition_name :=
    scmsa_handset_mobility_data_build.fn_get_partition_name (
    p_table_name => 'STORES_COMM_MOB_SUB_INFO',
    p_search_string => m1.year_val);
    FOR m2
    IN (SELECT DISTINCT
    'M' || TO_CHAR (batch_create_dt, 'MM') AS month_val
    FROM stores_comm_mob_sub_temp
    WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val)
    LOOP
    lv_subpartition_name :=
    scmsa_handset_mobility_data_build.fn_get_subpartition_name (
    p_table_name => 'STORES_COMM_MOB_SUB_INFO',
    p_partition_name => lv_partition_name,
    p_search_string => m2.month_val);
                        DBMS_OUTPUT.PUT_LINE('The lv_subpartition_name => '||lv_subpartition_name||' and lv_partition_name=> '||lv_partition_name);
    IF lv_subpartition_name IS NULL
    THEN
                             DBMS_OUTPUT.PUT_LINE('INSIDE IF => '||m2.month_val);
    INSERT INTO STORES_COMM_MOB_SUB_INFO T1 (
    t1.ntlogin,
    t1.first_name,
    t1.last_name,
    t1.job_title,
    t1.store_id,
    t1.batch_create_dt)
    SELECT t2.ntlogin,
    t2.first_name,
    t2.last_name,
    t2.job_title,
    t2.store_id,
    t2.batch_create_dt
    FROM stores_comm_mob_sub_temp t2
    WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val
    AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
    m2.month_val;
    ELSIF lv_subpartition_name IS NOT NULL
    THEN
                        DBMS_OUTPUT.PUT_LINE('INSIDE ELSIF => '||m2.month_val);
    MERGE INTO (SELECT *
    FROM stores_comm_mob_sub_info
    SUBPARTITION (lv_subpartition_name)) T1 --> Issue Here
    USING (SELECT *
    FROM stores_comm_mob_sub_temp
    WHERE TO_CHAR (batch_create_dt, 'YYYY') =
    m1.orig_year_val
    AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
    m2.month_val) T2
    ON (T1.store_id = T2.store_id
    AND T1.ntlogin = T2.ntlogin)
    WHEN MATCHED
    THEN
    UPDATE SET
    t1.postpaid_totalqty =
    (NVL (t1.postpaid_totalqty, 0)
    + NVL (t2.postpaid_totalqty, 0)),
    t1.sales_transaction_dt =
    GREATEST (
    NVL (t1.sales_transaction_dt,
    t2.sales_transaction_dt),
    NVL (t2.sales_transaction_dt,
    t1.sales_transaction_dt)),
    t1.batch_create_dt =
    GREATEST (
    NVL (t1.batch_create_dt, t2.batch_create_dt),
    NVL (t2.batch_create_dt, t1.batch_create_dt))
    WHEN NOT MATCHED
    THEN
    INSERT (t1.ntlogin,
    t1.first_name,
    t1.last_name,
    t1.job_title,
    t1.store_id,
    t1.batch_create_dt)
    VALUES (t2.ntlogin,
    t2.first_name,
    t2.last_name,
    t2.job_title,
    t2.store_id,
    t2.batch_create_dt);
    END IF;
    END LOOP;
    END LOOP;
    COMMIT;
    end;
    Much appreciate your inputs here.
    Thanks,
    MK.
    (SORRY TO POST THE SAME QUESTION TWICE).
    Edited by: Maddy on May 23, 2013 10:20 PM

    Duplicate question

  • Error executing a stored procedure from SSIS using the MERGE statement between databases

    Good morning,
    I'm trying to execute from SSIS a stored procedure that compares the content of two tables on different databases in the same server and updates one of them. To perform this action, I've created a stored procedure in the destination database and I'm
    comparing the data between tables with the MERGE statement. When I execute the procedure on the destination database the error that I obtain is:
    "Msg 916, Level 14, State 1, Procedure RefreshDestinationTable, Line 13
    The server principal "XXXX" is not able to access the database "XXXX" under the current security context."
    Some things to take in account:
    1. I've created a temporary table on the same destination database to check if the problem was on the MERGE statement and it works fine.
    2. I've created the procedure with the option "WITH EXECUTE AS DBO".
    I've read that it can be a problem of permissions but I don't know if I'm executing the procedure from SSIS to which user/login I should give permissions and which.
    Could you give me some tip to continue investigating how to solve the problem?
    Thank you,
    Virgilio

    Read Erland's article http://www.sommarskog.se/grantperm.html
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Help needed in MERGE statement

    Hi,
    I am new to PL/SQL, I want to update a table called "final_test" based on the below query result.
    1. I want to check whether that particular record is present or not in my "final_test" table.
    2. If its present in the "final_test" table and the process_status got changed then I want to update that alone in my "final_test" table.
    3. If its not present then I want to insert that record into my "final_test" table.
    Basically I am retrieving the report and its status for a particular date.
    select
    b.id,
    a.name,
    a.t_name,
    c.process_status,
    c.time_process
    from rep_tab_map a, j_tab_map b, proc_status c
    where a.t_name=b.t_name
    and b.id=c.id (+)
    and trunc(c.date_start)=trunc(sysdate -1)
    group by a.name,b.id,c.process_status,c.time_process,a.t_name
    order by 2
    I thought of using Merge statement but i am not sure what i have to use in ":USING" and "ON" clause.
    Please help me with MERGE or with someother way.
    Thanks

    Assuming final_test has same structure as select list in your query:
    merge
      into final_test a
      using (
             select  b.id,
                     a.name,
                     a.t_name,
                     c.process_status,
                     c.time_process
               from  rep_tab_map a,
                     j_tab_map b,
                     proc_status c
               where a.t_name=b.t_name
                 and b.id=c.id(+)
                 and trunc(c.date_start)=trunc(sysdate -1)
               group by a.name,b.id,c.process_status,c.time_process,a.t_name
            ) b
      on (b.id = a.id)
      when matched then update set a.name = case a.process_status
                                              when b.process_status then a.name
                                              else b.name
                                            end,
                                   a.t_name = case a.process_status
                                                when b.process_status then a.t_name
                                                else b.t_name
                                              end,
                                   a.process_status = b.process_status,
                                   a.time_process = case a.process_status
                                                      when b.process_status then a.time_process
                                                      else b.time_process
                                                    end
      when not matched then insert(
                                   a.id,
                                   a.name,
                                   a.t_name,
                                   a.process_status,
                                   a.time_process
                            values(
                                   b.id,
                                   b.name,
                                   b.t_name,
                                   b.process_status,
                                   b.time_process
    /SY.

  • Problem in Merge statement

    Hi All,
    I am using merge statement to update 30000 records from the tables having 55 lacs records.
    But it is taking much time as i have to kill the session after 12 hours,as it was still going on.
    If,Same update i m doing using cursors,it will finish in less than 3 hours.
    Merge i was using is :-
    MERGE INTO Table1 a
    USING (SELECT MAX (TO_DATE ( TO_CHAR (contact_date, 'dd/mm/yyyy')
    || contact_time,
    'dd/mm/yyyy HH24:Mi:SS'
    ) m_condate,
    appl_id
    FROM Table2 b,
    (SELECT DISTINCT acc_no acc_no
    FROM Table3, Table1
    WHERE acc_no=appl_id AND delinquent_flag= 'Y'
    AND financier_id='NEWACLOS') d
    WHERE d.acc_no = b.appl_id
    AND ( contacted_by IS NOT NULL
    OR followup_branch_code IS NOT NULL
    GROUP BY appl_id) c
    ON (a.appl_id = c.appl_id AND a.delinquent_flag = 'Y')
    WHEN MATCHED THEN
    UPDATE
    SET last_contact_date = c.m_condate;
    In this query table 1 has 30000 records and table2 and table 3 have 3670955 and 555674 records respectively.
    Please suggest,what i am doing wrong in merge,because as per my understanding merge statement is much better than updates or updates using cursors.
    Required info is as follows:
    SQL> show parameter user_dump_dest
    NAME TYPE VALUE
    user_dump_dest string /opt/oracle/admin/FINCLUAT/udu
    mp
    SQL> show parameter optimizer
    NAME TYPE VALUE
    optimizer_dynamic_sampling integer 2
    optimizer_features_enable string 10.2.0.4
    optimizer_index_caching integer 0
    optimizer_index_cost_adj integer 100
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    SQL> show parameter db_file_multi
    NAME TYPE VALUE
    db_file_multiblock_read_count integer 16
    SQL> show parameter db_block_size
    NAME TYPE VALUE
    db_block_size integer 8192
    SQL> column sname format a20
    SQL> column pname format a20
    SQL> column pval2 format a20
    SQL> select
    2 sname     ,
    3 pname     ,
    4 pval1     ,
    5 pval2
    6 from
    7 sys.aux_stats$;
    sys.aux_stats$
    ERROR at line 7:
    ORA-00942: table or view does not exist
    Elapsed: 00:00:00.05
    SQL> explain plan for
    2 -- put your statement here
    3 MERGE INTO cs_case_info a
    4      USING (SELECT MAX (TO_DATE ( TO_CHAR (contact_date, 'dd/mm/yyyy')
    5                          || contact_time,
    6                          'dd/mm/yyyy HH24:Mi:SS'
    7                          )
    8                ) m_condate,
    9                appl_id
    10           FROM CS_CASE_DETAILS_ACLOS b,
    11                (SELECT DISTINCT acc_no acc_no
    12                FROM NEWACLOS_RESEARCH_HIST_AYLA, cs_case_info
    13                WHERE acc_no=appl_id AND delinquent_flag= 'Y'
    14                AND financier_id='NEWACLOS') d
    15           WHERE d.acc_no = b.appl_id
    16           AND ( contacted_by IS NOT NULL
    17                OR followup_branch_code IS NOT NULL
    18                )
    19           GROUP BY appl_id) c
    20      ON (a.appl_id = c.appl_id AND a.delinquent_flag = 'Y')
    21      WHEN MATCHED THEN
    22      UPDATE
    23           SET last_contact_date = c.m_condate
    24      ;
    Explained.
    Elapsed: 00:00:00.08
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)|
    | 0 | MERGE STATEMENT | | 47156 | 874K| | 128K (1)|
    | 1 | MERGE | CS_CASE_INFO | | | | |
    | 2 | VIEW | | | | | |
    | 3 | HASH JOIN | | 47156 | 36M| 5672K| 128K (1)|
    | 4 | VIEW | | 47156 | 5111K| | 82339 (1)|
    | 5 | SORT GROUP BY | | 47156 | 4236K| 298M| 82339 (1)|
    | 6 | HASH JOIN | | 2820K| 247M| 10M| 60621 (1)|
    | 7 | HASH JOIN | | 216K| 7830K| | 6985 (1)|
    | 8 | VIEW | index$_join$_012 | 11033 | 258K| | 1583 (1)|
    | 9 | HASH JOIN | | | | | |
    | 10 | INDEX RANGE SCAN | IDX_CCI_DEL | 11033 | 258K| | 768 (1)|
    | 11 | INDEX RANGE SCAN | CS_CASE_INFO_UK | 11033 | 258K| | 821 (1)|
    | 12 | INDEX FAST FULL SCAN| IDX_NACL_RSH_ACC_NO | 5539K| 68M| | 5382 (1)|
    | 13 | TABLE ACCESS FULL | CS_CASE_DETAILS_ACLOS | 3670K| 192M| | 41477 (1)|
    | 14 | TABLE ACCESS FULL | CS_CASE_INFO | 304K| 205M| | 35975 (1)|
    Note
    - 'PLAN_TABLE' is old version
    24 rows selected.
    Elapsed: 00:00:01.04
    SQL> rollback;
    Rollback complete.
    Elapsed: 00:00:00.03
    SQL> set autotrace traceonly arraysize 100
    SQL> alter session set events '10046 trace name context forever, level 8';
    ERROR:
    ORA-01031: insufficient privileges
    Elapsed: 00:00:00.04
    SQL>      disconnect
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>      spool off
    Edited by: user4528984 on May 5, 2009 10:37 PM

    For one thing, alias your tables and use that in the column specifications (table1.column1 = table2.column3 for example)...
          SELECT
             DISTINCT
                acc_no acc_no
          FROM Table3, Table1
          WHERE acc_no            = appl_id
          AND   delinquent_flag   = 'Y'
          AND   financier_id      = 'NEWACLOS'We don't know what your tables look like, what columns come from where. Try and help us help you, assume we know NOTHING about YOUR system, because more likely than naught, that's going to be the case.
    In addition to that, please read through this which will give you a better-er idea of how to post a tuning related question, you've not provided near enough information for us to intelligently help you.
    HOW TO: Post a SQL statement tuning request - template posting

  • Using Delete in Merge Statement

    As merge statement inserts and updates the target data related to the source data but what if the target table contains some additional rows. I mean now both the target table and source tables are not the same. How to do it ?

    mshamirtaloo wrote:
    As merge statement inserts and updates the target data related to the source data but what if the target table contains some additional rows. I mean now both the target table and source tables are not the same. How to do it ?Well, there's nothing to say that the source and target need to be 'the same' so really not sure what you're asking.
    As of Oracle 10 the MERGE command allows for insert, update and delete operations.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_9016.htm#SQLRF01606

  • FORALL MERGE statement works in local database but not over database link

    Given "list", a collection of NUMBER's, the following FORALL ... MERGE statement should copy the appropriate data if the record specified by the list exists on both databases.
    forall i in 1..list.count
    merge into tbl@remote t
    using (select * from tbl
    where id = list(i)) s
    on (s.id = t.id)
    when matched then
    update set
    t.status = s.status
    when not matched then
    insert (id, status)
    values (s.id, s.status);
    But this does not work. No exceptions, but target table's record is unchanged and "sql%rowcount" is 0.
    If the target table is in the local database, the exact same statement works:
    forall i in 1..list.count
    merge into tbl2 t
    using (select * from tbl
    where id = list(i)) s
    on (s.id = t.id)
    when matched then
    update set
    t.status = s.status
    when not matched then
    insert (id, status)
    values (s.id, s.status);
    Does anyone have a clue why this may be a problem?
    Both databases are on Oracle 10g.
    Edited by: user652538 on 2009. 6. 12 오전 11:29
    Edited by: user652538 on 2009. 6. 12 오전 11:31
    Edited by: user652538 on 2009. 6. 12 오전 11:45

    Should throw an error in my opinion. The underlying reason for not working is basically because of
    SQL> merge into   t@remote t1
         using   (    select   sys.odcinumberlist (1) from dual) t2
            on   (1 = 1)
    when matched
    then
       update set i = 1
    Error at line 4
    ORA-22804: remote operations not permitted on object tables or user-defined type columnsSame reason as e.g.
    insert into t@remote select * from table(sys.odcinumberlist(1,2,3))doesn't work.

  • Merge Statement in ABAP

    Dear Gurrus,
    i am having a trouble in using oracle merge statement in abap, the moment i use where clause in the bottom it  gives me an oracle error
    EXEC SQL.
      MERGE INTO SAP_GL_ACCOUNT@GETZDB a
      USING SKA1 b
        ON (A.gl_code= B.SAKNR)
      WHEN MATCHED THEN
        UPDATE SET a.posting_block =  B.XSPEB,
                   a.locked        =  B.XSPEA,
                   A.BALANCE_SHEET =  B.XBILK
         WHEN NOT MATCHED THEN
           insert   (gl_code,
                     DESCRIPTION,
                     posting_block,
                     locked,
                     balance_sheet)
          VALUES (b.SAKNR,'shadab',B.XSPEB,B.XSPEA,B.XBILK)
          where b. mandt = 950      I am talking about this line
             ENDEXEC.
    the Moment  i include WHERE clause in the botton before ENDEXEC it generates as error
    " Database error text........: "ORA-00904: "A3"."MANDT": invalid  identifier#ORA-02063: preceding line from GETZDB".
    although its a basic feature of Oracle to inclue where clauses in insert or update in merge, but here it is generating an error.

    Hello Shadab,
    As per my understanding of this oracle native sql code.
    everything is fine except the use of direct value i.e 950 .
    System is not able to process this value .
    This normally happens even in normal abap sql statements also.
    The better solution could be to declare a variable with the
    same data type as "mandt" and then pass this "950" value into that
    variable and then use this variable in the where clause instead of directly
    passing the value.
    i.e data:l_var type mandt vlaue '950'.
    The other option could be to use the same hard coded
    value but use this value in the where clause in quotations i.e.,
    '950' instead of 950.
    I hope this would solve your purpose, If not please reply me back.
    thanks,
    M.Naveen Kumar.

  • Problem using TAPI triggers and merge statement

    Hi,
    I use Designer tapi triggers on a table. When I try to execute a merge statement, I get the following error:
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value.
    Is there a restriction when using TAPI triggers and merge statements that anyone is aware of?

    No restrictions on MERGE commands that I know of. I have, however, seen the TAPI give inexplicable ORA-06502 errors. It would help to know what line in which procedure or trigger gave the error. That information should have been in the error stack.

  • Problem in merge statement -ORA-27432 Step does not exist for chain

    Hi
    I m getting ORA-27432 Step does not exist for chain error in merge statement.Please explain the same.
    MERGE INTO fos.pe_td_hdr_sd B
    USING (
             SELECT ACTIVE, ADDUID, ADDUIDTIME,TDKEY         FROM pe.pe_td_hdr
              WHERE  (adduidtime like '20070104%' or edituidtime like '20070104%')
              AND NVL(legacy_td,'N')<>'Y'
              AND SUBSTR(adduidtime,1,4)='2007'
              AND AMENDMENT_NO=0)A ON ( B.TDKEY = A.TDKEY)
      WHEN MATCHED THEN
        UPDATE SET B.ACTIVE=A.ACTIVE,
    B.ADDUID=A.ADDUID,
            B.ADDUIDTIME=A.ADDUIDTIME
      WHEN NOT MATCHED THEN
                      INSERT
                              B.ACTIVE,
                              B.ADDUID,
                              B.ADDUIDTIME)
                        VALUES(
                              A.ACTIVE,
                              A.ADDUID,
                              A.ADDUIDTIME)This query is a short version of the main query.It is same but having 180 columns in original table.

    What version of Oracle are you using? This message does not appear in my 10.1 Error Messages document, but the other messages in that range seem to be about DBMS_SCHEDULER.
    Are you using scheduler somewhere around where you are getting the error message?
    John

  • Error logging in merge statement

    how to handle error logging in merge statement??
    thanks in advance!!!

    Welcome to the forum!
    Whenever you post please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    >
    how to handle error logging in merge statement??
    >
    Do it the way the documentation tells you to.
    See the error_logging_clause of the MERGE statement in the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
    It contains an example of using error logging with MERGE
    >
    error_logging_clause
    The error_logging_clause has the same behavior in a MERGE statement as in an INSERT statement. Refer to the INSERT statement error_logging_clause for more information.
    See Also:
    "Inserting Into a Table with Error Logging: Example"

  • Order not maintained in MERGE statement

    I am using a MERGE statement as follows:
    MERGE INTO target T
    USING ( select * from source order by data_id ) S
    on ( T.data_id = S.data_id )
    when matched then update
    set t.code = s.code
    when not matched then insert
    (t.code, t.data_id )
    values
    (S.code, S.data_id )
    But the newly inserted records in the target table are not ordered in the same order as the source table.
    E.g
    source
    data_id(pk)     code     
    1     1
    2     2
    3     2
    target
    pk_col data_id     code
    1     3     1
    2     1     2
    3     1     2
    I was expecting records in noth tables to be sorted in order of data_id
    Is this a limitation of merge statement or is there any workaround.

    bony wrote:
    I was expecting records in noth tables to be sorted in order of data_id
    Is this a limitation of merge statement or is there any workaround.No, it is not a limitation. It is 101 of relational databases - there is no row order in table rows. Same query can return rows in a different order next time you run it unless ORDER BY is specified.
    SY.

  • Merge Statement !!!! difference in Oracle 9i and Oracle XE

    Hi All ,
    I am using a Merge statement for multiplying a column......which works fine in XE but not in Oracle 9i
    CODE
    *======*
    MERGE INTO MULTIPLY T USING
    (SELECT CONV,ITEM FROM MULTIPLY WHERE TYP='P') X ON
    (T.ITEM= X.ITEM)
    WHEN MATCHED THEN UPDATE SET T.CONV =X.CONV * T.CONV WHERE TYP!='P'
    What shud I need to do in order to get the same result in Oracle 9i.....
    I understand that I used use one more line WHEN NOT MATCHED ..... but I am getting an Error in the Update statement where clause , whether it is not possible to combine where clause in the Merge statement
    Sample data:
    ITM     CONV     TYP
    ===============
    A     2     
    A     5     
    A     4     P
    A     2     
    Output; which I am getting in Oracle XE but not in Oracle 9i
    ======================================
    ITM CONV TYP
    === ==== =====
    A 2 *4
    A 5 *4
    A 4 P
    A 2*4
    BANNER
    ==========
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    BANNER_
    Oracle9i Enterprise Edition Release 9.2.0.5.0 - Production
    PL/SQL Release 9.2.0.5.0 - Production
    CORE     9.2.0.6.0     Production
    TNS for 32-bit Windows: Version 9.2.0.5.0 - Production
    NLSRTL Version 9.2.0.5.0 - Production
    Can you please guide me on this
    Thanks
    Ananda
    Edited by: Ananda on Nov 13, 2008 3:49 PM
    Edited by: Ananda on Nov 13, 2008 8:56 PM

    Hi ,
    Thanks for ur reply....
    I am getting an Error as Missing Keyword and points to the WHERE in the update statement ..............
    Am i doin anything wrong here in the syntax ...........but if i do the same without the where statement in Update ....... Merge works fine but with wrong output
    Thanks
    Ananda
    Edited by: Ananda on Nov 13, 2008 4:06 PM

Maybe you are looking for