Any Substitution of Merge statement ?

Hi All,
I just would like to know,is it any way to tune the Merge Update or Insert statement based on match ?.I am having one proc where i am using merge statetment and checking based condition it checks whether the record is present if yes then update else insert it,almost 100 k rows is there and this proc takes long time (around 6-7 hrs) to get complete,
so i just want to know is it any way i can tune my query or any other substitution i can use it instead of MERGE.
many thanks n advance..
Anwy

There should be an applicable index for the destination-table. The index should have a good selectivity with the columns compared in the match condition. Best is to use a unique key or primary key - index.
Additionally the statistics of the destination-table should be up to date (dbms_stats).
Edited by: hm on 11.11.2010 02:25

Similar Messages

  • Error while using Merge statement

    Hi,
    Can any one please look at the merge statement and help me understand the error.Thanks in advance.
    MERGE /*+ APPEND */
    INTO intf_lpa_master m
    USING (SELECT std_district_student_id,
    std_grade_code,
    sub_test,
    test_date,
    performance_lvl_code,
    test_lang_code,
    v_student_id,
    v_test_id,
    v_lang_cd,
    v_plc,
    valid_test_date,
    -- school_year,
    -- school_id,
    valid_src_stu_id,
    test_code
    FROM intf_lpa_master_vw
    MINUS
    SELECT std_district_student_id,
    std_grade_code,
    sub_test,
    test_date,
    performance_lvl_code,
    test_lang_code,
    v_student_id,
    v_test_id,
    v_lang_cd,
    v_plc,
    valid_test_date,
    -- school_yr,
    -- school_id,
    valid_src_stu_id,
    test_code
    FROM intf_lpa_master
    WHERE active_flag = 'Y') v
    ON ( m.std_district_student_id = v.std_district_student_id
    AND m.sub_test = v.sub_test
    AND m.test_date = v.test_date)
    WHEN MATCHED
    THEN
    UPDATE SET m.std_grade_code = v.std_grade_code,
    m.performance_lvl_code = v.performance_lvl_code,
    m.test_lang_code = v.test_lang_code,
    m.active_flag = 'Y', -- if we are touching this record, it is to be active.
    m.error_message = NULL, -- refresh these, to properly reconsider records.
    m.create_date = SYSDATE,
    m.record_id = intf_lpa_master_seq.NEXTVAL,
    m.process_row = 'U',
    m.last_update_date = SYSDATE,
    m.last_update_user = 'PRE_PROCESS_LPA - UPDATE',
    -- m.job_id = c_run_id ,
    m.validation_step = NULL, -- refresh these, to properly reconsider records.
    m.v_student_id = v.v_student_id,
    m.v_test_id = v.v_test_id,
    m.v_lang_cd = v.v_lang_cd,
    m.v_plc = v.v_plc,
    m.valid_test_date = v.valid_test_date,
    -- m.school_year = v.schloo_year,
    -- m.school_id = v.school_id,
    m.valid_src_stu_id = v.valid_src_stu_id,
    m.test_code = v.test_code
    WHEN NOT MATCHED
    THEN
    INSERT (
    m.std_district_student_id,
    m.std_grade_code,
    m.sub_test,
    m.test_date,
    m.performance_lvl_code,
    m.test_lang_code,
    m.active_flag,
    m.error_message,
    m.create_date,
    m.record_id,
    m.process_row,
    m.last_update_date,
    m.last_update_user,
    -- m.job_id,
    m.validation_step,
    m.v_student_id,
    m.v_test_id,
    m.v_lang_cd,
    m.v_plc,
    m.valid_test_date,
    -- m. school_year,
    -- m. school_id,
    m.valid_src_stu_id,
    m.test_code)
    VALUES (
    v.std_district_student_id,
    v.std_grade_code,
    v.sub_test,
    v.test_date,
    v.performance_lvl_code,
    v.test_lang_code,
    'Y',
    NULL,
    SYSDATE,
    intf_lpa_master_seq.NEXTVAL,
    'I',
    SYSDATE,
    'PRE_PROCESS_LPA - INSERT',
    -- c_run_id,
    NULL,
    v.v_student_id,
    v.v_test_id,
    v.v_lang_cd,
    v.v_plc,
    v.valid_test_date,
    -- v. school_year,
    -- v. school_id,
    v.valid_src_stut_id,
    v.test_code);
    Error Message :
    ORA-06553 : PLS-306:wrong number or types of arguments in call to 'V'

    There are a couple of thngs wrong here. In the when matched insert column list, you cannot qualify the field name with the table alias. It should be just:
    insert (std_district_student_id, std_grade_code, sub_test ...)Are v_student_id, v_test_id, v_lang_cd, and v_plc really columns in the intf_lpa_master table? I am more used to seeing v_name as a variable naming convention than a column name, but I could be wrong.
    John

  • Help needed in the Merge Statement

    Hi All,
    I am using MERGE statement in my program. I want to maintain the log for the duplicate reords mean maintain the log for those reocrds which are updated in the merge statement.
    Can any one help me in this that how can i maintain the log?
    Thanks for your help in advance.
    kind Regards,

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:35615502072484

  • How to use Inner join of table as Source in Merge statement in SQL

    Hi All,
        I am trying to make source as multiple tables output using Join while coding there is no any syntax error but when i am executing this statement is giving following error
    Following is the query 
    Merge Into EmpDept Target
    Using (select E.Address,e.Design,e.EmailId,e.EmpId,e.Ename,e.ManagerId, e.Salary,D.DeptId,D.DeptName,D.Location from Employee E Inner join Dept D on E.DeptId=D.DeptId )As Source (Address,Design,EmailId,EmpId,EName,ManagerId,Salary,DeptId,DeptName,Location)
    On Source.EmpId=Target.EmpId
    when not matched then
    Insert (Target.Address,Target.Design,Target.EmailId,Target.EmpId,Target.Ename,Target.ManagerId, Target.Salary,Target.DeptId,Target.DeptName,Target.Location)
    values
    (Address,Design,EmailId,EmpId,EName,ManagerId, Salary,DeptId,DeptName,Location)
    When matched then 
    Update set Target.Address = Source.Address ,Target.Design = Source.Design,Target.EmailId      = Source.EmailId     ,Target.Ename       = Source.Ename      ,Target.ManagerId = Source.ManagerId , Target.Salary        = Source.Salary       ,Target.DeptId      = Source.DeptId      ,Target.DeptName = Source.DeptName ,Target.Location    = Source.Location;
    This is error while executing the above merge statement 
    The insert column list used in the MERGE statement cannot contain multi-part identifiers. Use single part identifiers instead.
    Please suggest me where i am wrong.. 
    Niraj Sevalkar

    MERGE INTO EmpDept Target
    Using (SELECT E.Address,
    e.Design,
    e.EmailId,
    e.EmpId,
    e.Ename,
    e.ManagerId,
    e.Salary,
    D.DeptId,
    D.DeptName,
    D.Location
    FROM Employee E
    INNER JOIN Dept D
    ON E.DeptId = D.DeptId) AS Source (Address, Design, EmailId, EmpId, EName, ManagerId, Salary, DeptId, DeptName, Location)
    ON Source.EmpId = Target.EmpId
    WHEN NOT matched THEN
    INSERT (Address,
    Design,
    EmailId,
    EmpId,
    Ename,
    ManagerId,
    Salary,
    DeptId,
    DeptName,
    Location)
    VALUES (Address,
    Design,
    EmailId,
    EmpId,
    EName,
    ManagerId,
    Salary,
    DeptId,
    DeptName,
    Location)
    WHEN matched THEN
    UPDATE SET Address = Source.Address,
    Design = Source.Design,
    EmailId = Source.EmailId,
    Ename = Source.Ename,
    ManagerId = Source.ManagerId,
    Salary = Source.Salary,
    DeptId = Source.DeptId,
    DeptName = Source.DeptName,
    Location = Source.Location;

  • Using hints in MERGE statement

    i have a merge statement
    in that statement for select clause i am using index hints
    can i use it
    whether that will increase the performance or the reverse will happen
    any comments

    Hints should always be your last option. First try tune the sql without using any hints, most of the cases you will be ok. Over time when the table statistics(ex. rows) changes considerably hints may be negative impact.

  • Merge Statement output

    Hi all,
    I am working on oracle9i
    I am using the Merge Statement to INS/UPD rows
    I am using loops to
    I am updating 29 rows as insert and 1 row a update
    Values are inserting and updating correctly in table
    But in Sql prompt
    I am getting the output as
    below
    12:03:54 SQL> execute Pr_Bdms_Cont_Insupd;
    1 rows merged.
    1 rows inserted.
    1 rows updated.
    PL/SQL procedure successfully completed.
    But i take out the loop i am getting exact result
    12:03:54 SQL> execute Pr_Bdms_Cont_Insupd;
    30 rows merged.
    29 rows inserted.
    1 rows updated.
    PL/SQL procedure successfully completed.
    Any help
    Below is my procedure
    and
    CREATE OR REPLACE PROCEDURE Pr_EMP_Insupd IS
    empID VARCHAR2(7);
    CURSOR C_empno IS SELECT empno FROM TEMP WHERE ROWNUM < 30;
    REC_BIN C_empid%ROWTYPE;
    BEGIN
    FOR REC_BIN IN C_empid LOOP
    empID := fn_emp_Id(REC_BIN.Bin);-- Calling function
    Merge INTO EMP E
    BGC
    USING (SELECT A.EMP_ID,B.SALARY,B.BONUS
    FROM EMP_IN A, TEMP B
    WHERE A.EMPNO = B.EMPNO
    AND A.EMP_ID = EMPID)NP
    ON(E.EMP_ID = NP.EMP_ID)
    WHEN MATCHED THEN UPDATE SET E.SALARY = NP.SALARY,
    E.BONUS = NP.BONUS
    WHEN NOT MATCHED THEN INSERT (E.EMP_ID,E.SALARY,E.BONUS,E.CREATED_DATE)
    VALUES (CASE Check_Upd_Ins.merge_counter(Check_Upd_Ins.c_inserting)
    WHEN 0 THEN E.EMP_ID
    END,
    E.SALARY,E.BONUS,SYSDATE);
    END LOOP;
    /* Use insert count... using ETL Package*/
    dbms_output.put_line(Check_Upd_Ins.get_merge_update_count(SQL%rowcount) || ' rows updated.');
    dbms_output.put_line(Check_Upd_Ins.get_merge_insert_count || ' rows inserted.');
    Check_Upd_Ins.reset_counters;
    COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR(-20000, SQLERRM(SQLCODE));
    END Pr_EMP_Insupd;

    Perhaps I can help you with this piece of code and this link :
    MERGE INTO bonuses D
    USING (SELECT employee_id, salary, department_id FROM employees
    WHERE department_id = 80) S
    ON (D.employee_id = S.employee_id)
    WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
    WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
    VALUES (S.employee_id, S.salary*0.1);
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/13_elems30.htm#37586
    Joel P�rez

  • Merge statement and insert into a third table

    I'm wondering if the merge statement will work in my case. I'm loading a file into a temporary table. I want to compare this temporary table with an existing source table (there are multiple source tables, I've thought of breaking them up into separate statements) and write out any differences to a third table. The third table would be used for future processing on the rows that are found to be different. Do you think this is possible using the merge command?

    Why use the merge command for that purpose?
    If you want to find out the differences of two tables and put the result into a third one then you should do
    insert into table_c
    query_a
    minus
    query_b
    or
    insert into table_c
    (query_a
    minus
    query_b)
    union all
    (query_b
    minus
    query_a)
    hth

  • Merge Statement Giving Error

    Hi Everyone,
    I am trying to use MERGE statement for my Data Load. But it is giving out an un-understandable error. It In the "ON" Part, it refuses to recognise the destination table columns...
    like I say ON(dest.Per_No = Src.Per_No), and it says "Invalid Identifier dest.Per_No"
    Any Ideas, am pasting shortened version of my SQL:
    ========================================
    SQL> ed
    Wrote file afiedt.buf
    1 MERGE INTO CIPIC.Dest P
    2 USING (SELECT Src1.ROW_ID AS PER_No,
    3 LTRIM(Src2.PARTY_ID,'0') AS ARN,
    4 ....
    9 FROM Src1,Src2,....
    12 WHERE MANY JOINS GO HERE) S
    16 ON (P.PER_No = S.PER_No AND P.A_Column = S.A_Column)
    17 WHEN MATCHED THEN UPDATE SET P.blah = S.blah1
    24 WHEN NOT MATCHED THEN INSERT (PER_No, A_Column,....)
    26 VALUES (S.PER_No, .A_Column, ......)
    SQL> /
    ON (P.PER_No = S.PER_No AND P.A_Column = S.A_Column)
    ERROR at line 16:
    ORA-00904: "P"."PER_No": invalid identifier

    See here
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_915a.htm#2080942
    >
    Restrictions on Updating a View
    You cannot specify DEFAULT when updating a view.
    You cannot update a column that is referenced in the ON condition clause.
    Rgds.

  • Doubt Regarding Merge Statement in Oracle

    Hi,
    I have an SP which takes 3 parameters Lets say
    (in_empid, in_empname,in_age)
    here in_empid corresponds to the empid ie primary key for update/insert
    Now which of the approach will be better. Will there be problem in using Merge statements for updates/insert
    1. Approach 1
    Add one more flag in parameters in_action . Now if in_action = 'U' then write an update statement.If in_action='I' then write insert stmnt
    2. Approach 2
    write a merge stmnt as follows
    merge into employee e using
    ( select in_empid, in_empname,in_age from dual ) b
    on  ( b.in_empid = e.empid)
    WHEN MATCHED THEN
      UPDATE SET e.ENAME = in_empname,
                           e.age = in_age
    WHEN NOT MATCHED THEN
      INSERT
      VALUES (in_empid,in_empname,in_age) something like that
    Which would be preferred? I mean is there any restriction that merge can be used only to merge 2 tables?what are the drawbacks of using Merge?
    Regds,
    S

    Hi cd,
    Thanks for the reply.
    Actaully I was keeping the front-end code also in mind.
    If we click an update button, then they will have to manage a flag till the end to say that transaction was update. whereas when its an insert of new record, they have to maintain a falg till end to imply that the transaction was insert.
    I want to avoid this so that they need not maintain additional flag.
    Hence I was thinking of using MERGE statement.
    Will there be any problem in using merge for such scenarios?
    Regds,
    S

  • DB procedure in Merge Statement

    Hi,
    Is there any way to use DB procedure inside of Merge Statement.
    Thanks & Regards
    Radha K

    Wrap your procedure in a function to be accessible from within SQL.

  • ORA 22813 in merge statement

    hi gems..good afternoon...
    My database version is 11.2.0.1.0 64 bit Solaris OS.
    I am facing an "ORA-22813: operand value exceeds system limits" while running a procedure.
    I have used loggers and found that it is getting failed in a MERGE statement.
    That merge statement is used to merge a table with a collection. the code is like below:
    MERGE /*+ INDEX(P BALANCE_HISTORIC_INDEX) */
        INTO BALANCE_HOLD_HISTORIC P
        USING TABLE(GET_BALANCE_HIST(V_MERGE_REC)) M
        ON (P.CUSTOMER_ID = M.CUSTOMER_ID AND P.BOOK_ID = M.BOOK_ID AND P.PRODUCT_ID = M.PRODUCT_ID AND P.SUB_BOOK_ID = M.SUB_BOOK_ID AND)
        WHEN MATCHED THEN
          UPDATE
             <set .....>
        WHEN NOT MATCHED THEN
          INSERT<.....>The parameter of the function GET_BALANCE_HIST(V_MERGE_REC) is a table type.
    Now the function GET_BALANCE_HIST(V_MERGE_REC) is a pipelined function and we have used that because the collection V_MERGE_REC may get huge with data.
    This proc was running fine from the beginning but from day before yesterday it was continously throwing ORA 22813 error in that line.
    please help..thanks in advance..

    hi paul..thanks for your reply...
    the function GET_BALANCE_HIST is not selecting data from any tables.
    What this pipeline function is doing is, it is taking the huge collection V_MERGE_REC as parameter and releasing its datas in pipelined form. The code for the functions is :
    CREATE OR REPLACE FUNCTION GET_BALANCE_HIST(P_MERGE IN TAB_TYPE_BALANCE_HISTORIC)
      RETURN TAB_TYPE_BALANCE_HISTORIC
      PIPELINED AS
      V_MERGE TAB_TYPE_BALANCE_HISTORIC := TAB_TYPE_BALANCE_HISTORIC();
    BEGIN
      FOR I IN 1 .. P_MERGE.COUNT LOOP
        V_MERGE.EXTEND;
        V_MERGE(V_MERGE.LAST) := OBJ_TYPE_BALANCE_HISTORIC(P_MERGE(I).CUSTOMER_ID,
                                                 P_MERGE(I).BOOK_ID,
                                                 P_MERGE(I).PRODUCT_ID,
                                                 P_MERGE(I).SUB_BOOK_ID,
                                                 P_MERGE(I).EARNINGS,
                                                 P_MERGE(I).EARNINGS_HOUSE,
                                                 P_MERGE(I).QUANTITY,
                                                 P_MERGE(I).ACCOUNT_INTEGER);
      END LOOP;
      FOR J IN 1 .. V_MERGE.COUNT LOOP
        PIPE ROW(OBJ_TYPE_BALANCE_HISTORIC(V_MERGE(I).CUSTOMER_ID,
                                                 V_MERGE(I).BOOK_ID,
                                                 V_MERGE(I).PRODUCT_ID,
                                                 V_MERGE(I).SUB_BOOK_ID,
                                                 V_MERGE(I).EARNINGS,
                                                 V_MERGE(I).EARNINGS_HOUSE,
                                                 V_MERGE(I).QUANTITY,
                                                 V_MERGE(I).ACCOUNT_INTEGER));
      END LOOP;
      RETURN;
    END;I think the error is comming because of the parameter value of V_MERGE_REC. Since it is huge, so loading that into memory is causing problem. But in this case, how can I resolve it?? Can I use a global temporary table for this??
    Please suggest...

  • Bogus Invalid Object in MERGE Statement

    Let me begin by saying that I have been working with MERGE since its inception, and I am familiar with the fundamental gotcha's. This problem is more inexplicable. (It's one of those things that I expect, when someone explains it, will be a DOH! moment.)
    I am building a one-time conversion script to merge an existing User table with a new User table. Since I am only in the development mode, I didn't want to modify the true table yet. So I made a copy of the table to work with, using the following familiar
    syntax.
    SELECT *
    INTO uam.User2
    FROM uam.[User]
    Imagine my surprise when the MERGE statement refused to recognize uam.User2 - although it recognizes uam.[User] just fine.
    In the interests of competeness, here is the MERGE Statement in question.
    MERGE  uam.[User2]
    as tgt
    USING (SELECT
    UserID
    ,FirstName
    ,LastName
    ,CompanyID
    ,AuthenticationID
    ,isActive
    ,PrimaryEmailID
    ,CreatedByUserName
    ,CreatedByDtim
    ,@User
    _User
    ,GETDATE()
    _GETDATE
    FROM #User
    ) as src
      ON tgt.UserID = (src.UserID * -1)
    WHEN NOT MATCHED
    THEN
    INSERT
    (FirstName
    ,LastName
    ,CompanyID
    ,AuthenticationID
    ,isActive
    ,PrimaryEmailID
    ,CreatedByUserName
    ,CreatedByDtim
    ,LastUpdatedUserName
    ,LastUpdatedDtim
    VALUES
    (src.FirstName
    ,src.LastName
    ,src.CompanyID
    ,src.AuthenticationID
    ,src.isActive
    ,src.PrimaryEmailID
    ,src.CreatedByUserName
    ,src.CreatedByDtim
    ,_User
    ,_GETDATE
    OUTPUT INSERTED.UserID
    ,tgt.UserID
    INTO #UserMapping;
    The procedure refuses to run, flagging the tgt.UserID as 
    Msg 4104, Level 16, State 1, Line 140
    The multi-part identifier "tgt.UserID" could not be bound.
    SSMS also flags the uam.[User2] on the MERGE line as "Invalid object name 'uam.User2'" on mouse-over.
    A few notes:
    I have a SELECT * FROM uam.User2 immediately before this MERGE, and it works just fine. And yes, it returns a UserID column.
    If I change the name from uam.User2 to uam.[User], it works just fine.
    I know the JOIN is a little strange (I really wanted just an INSERT where I could see the original UserID and the newly inserted UserID together, and INSERT will not let me OUTPUT directly from a table - hence the MERGE), but I also tried it with a straight-up
    tgt.UserID = src.UserID. Nothing changed about the errors.
    I also went back and re-created the uam.User2 table directly from the code that built uam.[User]. Nothing changed.
    I'm flummoxed. This has all the earmarks of a "well-that-was-dumb" coding error, but for the life of me I cannot see what would change between using these two tables, since one is a copy of the other...
    Any insight would be much appreciated!
    Duncan Davenport

    OK, I have it.
    DOH!  (told ya)
    So, while intellisense (typically) flags this table as not existing, that's just Intellisense doing the nonsense it always does. This obfuscated the ACTUAL error - which was the wrong schema defined in the output clause. The error itself pointed at the wrong
    line (nothing new there either). Once I fixed the OUTPUT clause, everything worked as expected - although SSMS is still putting squiggly red lines under everything that is working anyway. Yeah, we've all seen THAT behavior - no big deal.
    Anyway, that's the answer. It's magic - in that the error messages specialize in misdirection :)...
    Closing this. (I wonder if I get credit for answering my own question?)

  • 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.

  • The new MERGE statement in Oracle 9i

    Has anyone used the new Merge statement to process large amounts of data? Currently we use PL/SQL to update/insert into our tables when we are loading large amounts of data (close to one million rows) because we can set commit points and avoid rollback problems. I am wondering if we use Merge instead how this will affect rollback? Are we still going to have to code for this problem?
    Thanks in advance!

    Thanks for the suggestions. Our problem is that the base table contains 50 million rows and seven indexes, and each month we try to insert/update one million rows. Some of the data in the base table is historical so if we implemented your solution we would lose any records not being updated.
    What I am really trying to determine is if the MERGE statement has any redo log ramifications. Will we run in rollback space problems if we implement it instead of running PL/SQL in the following format:
    FOR cur_rec in c1 LOOP
    UPDATE table a
    SET col a = cur_rec.col a, ...
    WHERE ...
    IF SQL%NOTFOUND THEN
    INSERT (col a , col b, col c...)
    VALUES (cur_rec.col a, cur_rec.col b...);
    END IF;
    We commit every 10,000 records (as determined by SQL%ROWCOUNT). This can be time comsuming and Oracle claims that the new MERGE command will avoid costly overhead and reduce data scans. However, I am concerned that we may hit rollback problems if we implement a straight SQL statement such as MERGE. Any thoughts?

  • Performance problem with MERGE statement

    Version : 11.1.0.7.0
    I have an insert statement like following which is taking less than 2 secs to complete and inserts around 4000 rows:
    INSERT INTO sch.tab1
              (c1,c2,c3)
    SELECT c1,c2,c3
       FROM sch1.tab1@dblink
      WHERE c1 IN (SELECT c1 FROM sch1.tab2@dblink);I wanted to change it to a MERGE statement just to avoid duplicate data. I changed it to following :
    MERGE INTO sch.tab1 t1
    USING (SELECT c1,c2,c3
       FROM sch1.tab1@dblink
      WHERE c1 IN (SELECT c1 FROM sch1.tab2@dblink) t2
    ON (t1.c1 = t2.c1)
    WHEN NOT MATCHED THEN
    INSERT (t1.c1,t1.c2,t1.c3)
    VALUES (t2.c1,t2.c2,t2.c3);The MERGE statement is taking more than 2 mins (and I stopped the execution after that). I removed the WHERE clause subquery inside the subquery of the USING section and it executed in 1 sec.
    If I execute the same select statement with the WHERE clause outside the MERGE statement, it takes just 1 sec to return the data.
    Is there any known issue with MERGE statement while implementing using above scenario?

    riedelme wrote:
    Are your join columns indexed?
    Yes, the join columns are indexed.
    You are doing a remote query inside the merge; remote queries can slow things down. Do you have to select all thr rows from the remote table? What if you copied them locally using a materialized view?Yes, I agree that remote queries will slow things down. But the same is not happening while select, insert and pl/sql. It happens only when we are using MERGE. I have to test what happens if we use a subquery refering to a local table or materialized view. Even if it works, I think there is still a problem with MERGE in case of remote subqueries (atleast till I test local queries). I wish some one can test similar scenarios so that we can know whether it is a genuine problem or some specific problem from my side.
    >
    BTW, I haven't had great luck with MERGE either :(. Last time I tried to use it I found it faster to use a loop with insert/update logic.
    Edited by: riedelme on Jul 28, 2009 12:12 PM:) I used the same to overcome this situation. I think MERGE needs to be still improved functionally from Oracle side. I personally feel that it is one of the robust features to grace SQL or PL/SQL.

Maybe you are looking for

  • Creating xml file from fields of a fmb

    Hi, What i want to do is to create a "generic" button (which can work for all forms of my application) which ables the application to create a xml file completed with all fields on my form. The matter is that i can't know by advance all fields of my

  • Issues with filling in a docuement

    I fill in the text boxes in a pdf in Adobe Reader on the Ipad, save the document however when I go to email the aforementioned document the contect boxes are blank - help please...

  • Font Showing Up in FontList, But Not Usable (Blank Text)

    Hey, I recently made myself a font to use in a project, but when I try to use it, it turns out to be an empty font. The font is showing up in the Titler, but behind it's name, in the font sample column, it's not showing any characters. I find this we

  • Query Manager Text Capacity is Full 6400 characters only

    hi again experts! I'd like to ask how  can I increase the Query Manager Text fields my query cant be complete. Anybody has an idea. Thank you. Clint

  • How do I change the default browser

    Can anyone tell me how I change the default browser which is invoked when I run a web application from Jdev3.1(under NT 4.0). When I run main.jsp from the JDev interface, it invokes IE 5.5. But, I want it to invoke and the application on Netscape 4.6