Return in the MERGE statement clause

Hello

I use Oracle 10 g Version

I tried the code using UPDATE with return Clause & MERGER with return below Clause.

I have not found ANY error while working with the UPDATE statement. Here is the code with the UPDATE statement

DECLARE
   TYPE empno_list IS TABLE OF emp.empno%TYPE;
   vempno_list   empno_list;
BEGIN
      UPDATE emp
         SET comm = 11
       WHERE deptno IN (SELECT deptno FROM dept)
   RETURNING empno
        BULK COLLECT INTO vempno_list;
   FOR i IN vempno_list.FIRST .. vempno_list.LAST
   LOOP
      DBMS_OUTPUT.put_line ('Values of EMP ' || vempno_list (i));
   END LOOP;
END;   

But PL/SQL error: ORA-00933: SQL not correctly completed command when you work with the MERGE statement

declare 
 type empno_list  is  table of emp.empno%type;
 vempno_list empno_list;
begin                
   merge into emp tgt 
      using dept src
        on (src.deptno =tgt.deptno)
        when matched then 
         update set tgt.comm=12
       returning tgt.empno bulk collect into vempno_list ;
       
        for i in vempno_list.first .. vempno_list.last loop
                dbms_output.put_line('Values of EMP '||vempno_list(i) ) ;
        end loop;
end;  

Please suggest me

Probably because BACK IN clause does not belong to the MERGE statement. It is available only for INSERT, UPDATE, and DELETE. Here's the quote from Oracle Documentation:

The static method RETURNING INTO article belongs to a DELETE , INSERT , or UPDATE statement. The dynamic RETURNING INTO article belongs to a EXECUTE IMMEDIATE statement.

And here is the link.

Back IN the Clause

It will be useful.

Ishan

Tags: Database

Similar Questions

  • Get error in the merge statement

    Version of Oracle, Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
    Hi gurus

    I am trying to perform the merge statement using the clause, but I get the error message, see below my sample data:

    Examples of data

    DROP TABLE OF BILLING;

    DROP TABLE GROUP_MST;

    DROP TABLE age_max;

    CREATE ARRAY OF BILLING

    (

    BILLING_ID NUMBER (5),

    RATE NUMBER (5),

    MAXIMUM_AGE NUMBER (5),

    package_id NUMBER (5)

    );

    INSERT

    IN BILLING

    (SELECT 11,1,10,100 FROM DUAL

    UNION ALL

    SELECT 12,2,15,100 FROM DUAL

    UNION ALL

    SELECT 13,3,20,100 FROM DUAL

    );

    CREATE TABLE GROUP_MST

    (group_number NUMBER (5), package_id NUMBER (5))

    );

    INSERT INTO GROUP_MST

    (SELECT DOUBLE 5 000 100

    );

    -------

    CREATE TABLE AGE_MAX

    (group_number NUMBER (5), max_age NUMBER (5))

    );

    INSERT

    IN AGE_MAX

    (SELECT 5000,60 FROM DUAL

    );

    Merge statement

    MERGE INTO DRC USING billing

    (WITH datum1 AS

    (SELECT A.group_number,

    b.billing_id,

    b.rate,

    b.maximum_age,

    b.package_id

    OF group_mst A,.

    b billing

    WHERE A.package_id = b.package_id

    ),

    datum2 AS

    (SELECT max_age, group_number FROM age_max

    )

    SELECT * FROM A, b WHERE A.group_number = b.group_number datum2 datum1

    )

    CBC ON (drc.billing_id = src.billing_id)

    WHEN MATCHED THEN

    UPDATE SET drc.maximum_age = src.max_age - 1;

    Error

    Error from the 33 in the command line:

    MERGE INTO DRC USING billing

    (WITH datum1 AS

    (SELECT A.group_number,

    b.billing_id,

    b.rate,

    b.maximum_age,

    b.package_id

    OF group_mst A,.

    b billing

    WHERE A.package_id = b.package_id

    ),

    datum2 AS

    (SELECT max_age, group_number FROM age_max

    )

    SELECT * FROM A, b WHERE A.group_number = b.group_number datum2 datum1

    )

    CBC ON (drc.billing_id = src.billing_id)

    WHEN MATCHED THEN

    UPDATE SET drc.maximum_age = src.max_age - 1

    Error in the command line: 50 column: 1

    Error report:

    SQL error: ORA-00918: column ambiguously defined

    00918 00000 - "ambiguously defined column.

    * Cause:

    * Action:

    Thanks in advance

    Concerning

    Shu

    WITH datum1 AS (SELECT A.group_number,

    b.billing_id,

    b.rate,

    b.maximum_age,

    b.package_id

    OF group_mst A, b billing

    WHERE A.package_id = b.package_id),

    datum2 AS (SELECT max_age, group_number FROM age_max)

    SELECT A.*, b.max_age, b.group_number as group_number_b - ERROR HERE

    OF datum1 A, b datum2

    WHERE A.group_number = b.group_number

  • insert/update County in the merge statement

    In the Merge statement, we can count the number of inserted rows and updated?

    ROWCOUNT SQL % simply returns the number of rows merged.

    It does not tell us the separately the line inserted and updated.

    # To insert the rowcount is the number of inserted rows for update is the number of rows updated, for the merger, that's the number of merged lines.

  • Buttons does not return to the early state in the state machine.

    Hello

    I downloaded a program that is used to back up data. I used a machine to States with different States. State 1 is initialization, where it moves automatically select the State, which allows to select one of the remaining States to copy the data. The selection is made by command buttons. Once u pressed a button, it goes to that respective State and in this state when you press the backup, the backup of data occurs. Once the backup is located the program goes back to the selection state. So far, it works fine. The problem then. Once he returned to the selection state after that copy was made, then none of the buttons are working properly. Then when it goes back to select State and I tried to select a State, nothing happens, not even the stop button works. I don't know why this is happen. Please help me solve this problem. Thanking you in advance.

    You have many States where you have the event structures ("All data" "given more older that '" young data that ' 'Defined Data') (worse there are two of them in "Data set")

    Each of these event structures are for a "Backup" mouse event down.  A singularity is now why you use a mouse event down on a button.  This really should be a value change event.  But this is not the big problem.

    The big problem is that all of these structures events are set to lock the front until the end of the case of the event.  Well, when you click the mouse down on this button, all 4 of these structures tail event this event.  If you are luckly, one of the event will execute and process the event.  Others, that you will never run because the state machine will not get through these cases.)

    You have multiple structures of event you VI and certainly not buried in the event.

    Reading guard and recommendations when using events in LabVIEW

    Then fix your VI architecture.  You must limit the structures of the event or a separate parallel loop, or to a single case of your state machine that your code will frequently return to, without any other user interaction, in order to service the structure of the event.

  • Bought B210a in the Portugal. Now to return to the United States. Problems?

    After four years of volunteering in the North of Portugal, where I bought my printer Photosmart Plus B210e (still in warranty) and my laptop HP Pavilion PC (out of warranty of six weeks), for reasons of ill health, I must return to the United States. [The printer that I had delivered statements did not survive the movers.]

    I have problems with my printer, or warranty with the purchase of ink cartridges?  I saw the messages of other people outside the United States, saying that their printers require different cartridges and more expensive - here, I use four 364, it is the same cartridge in the USA?

    HP/USA will accept a guarantee of common market HP/ESA (given that HP has all printers manufactured in China, there should be no problem, but...).

    Unfortunately, I live on a medical pension, which means that I don't want to buy expensive equipment that I already bought and paid for.

    Thank you very much - this is my first time on this forum.

    FCZ +.

    You can continue to use the cartridges in the printer and spare cartridges you have.  Once you miss if ink and the need to replace a cartridge you need to Contact HP to ask a "regionalization Reset." Do not charge for this, it is covered under the warranty of the cartridge. You will need to have access to your computer and printer then on line with HP. You will also need to have a set of cartridges for the new region, once completed reset cartridges of region of origin no longer works.  Webpage of HP on the subject is here.

    The cartridges in the United States will be 564.

    I don't know how the EU guarantee would transfer to the United States, you must Contact HP.

  • Different result by using the MERGE statement

    I have 2 SQL statements:

    MERGE INTO PT_CQS_AGGR APC

    With the HELP of PT_CQS_AGGR_TEMP Lady

    WE (concat (concat(pca.from_city_id,pca.to_city_id), pca.query_timestamp_hh) = concat (concat(pcah.from_city_id,pcah.to_city_id), pcah.query_timestamp_hh))

    WHEN MATCHED THEN

    Setting a DAY SET pca.search_count = pca.search_count + pcah.search_count

    WHEN NOT MATCHED THEN

    VALUES of INSERTION (to_city_id, query_timestamp_hh, from_city_id, search_count) (pcah.from_city_id, pcah.to_city_id, pcah.query_timestamp_hh, pcah.search_count);

    AND

    MERGE INTO PT_CQS_AGGR APC

    With the HELP of PT_CQS_AGGR_TEMP Lady

    WE (pca.from_city_id = pcah.from_city_id AND pca.to_city_id = pcah.to_city_id AND pca.query_timestamp_hh = pcah.query_timestamp_hh)

    WHEN MATCHED THEN

    Setting a DAY SET pca.search_count = pca.search_count + pcah.search_count

    WHEN NOT MATCHED THEN

    VALUES of INSERTION (to_city_id, query_timestamp_hh, from_city_id, search_count) (pcah.from_city_id, pcah.to_city_id, pcah.query_timestamp_hh, pcah.search_count);

    First statement correctly the merged data, but use FULL TABLE SCANS, so it's rather slow. Second statement using a UNIQUE INDEX on the columns from_city_id, to_city_id, and query_timestamp_hh on the MAP of EXPLAIN, but during the execution of I've got ORA-00001: unique constraint (PODOWNER. IDX_CQS_AGGR_3COL) violated. What is the problem with the second statement - especially with this line:

    WE (pca.from_city_id = pcah.from_city_id AND pca.to_city_id = pcah.to_city_id AND pca.query_timestamp_hh = pcah.query_timestamp_hh)

    Can I use a more complex condition in the MERGE statement? Because it seems that not all the conditions have been taken...

    ???

    Select pcah.from_city_id, pcah.to_city_id, PT_CQS_AGGR_TEMP Lady pcah.query_timestamp_hh

    less

    Select pca.from_city_id, pca.to_city_id, pca.query_timestamp_hh PT_CQS_AGGR pca

    somewhere the conditions limiting the time.

    (or whatever the columns make up the stress of failing)

    In addition, select for each column in the constraint of failure where the column is null.  If one of these columns is null, equality fails, even if both are null, because null <> null.  So you will get a "no match" if all values are the same and it is set to null.

    Edit: Oh, slap forehead, that is why one works and the complete analysis.  As SomeoneElse said, it normalizes the type of data and concatenates, comparison null to no effect and refusing all usual index.

  • Error in the Merge statement using dblink

    Hello

    I am facing the following error when you use the merge statement using the dblink.

    ORA-02069: global_names must be set to true for this operation parameter.

    I can use the same dblink in my select insert and update statements but when I try to use merge then he invites the error said, is also not any syntax error as same statement can be used on the same tables of database instead of dblink.

    Please suggest any help will be much appreciated.

    Thanks in advance

    Hi Aqeel

    If insert and update statements work well through links db, then it should not be a problem with the merge statement. But if you are faced with the question, so please check the entire sql statement with tnsnames on both sides. Please share the tnsnames for the two dbs with dblink ddl.

    Concerning

    Jihane Narain Sylca

  • Question about the MERGE statement

    Hi all

    I have a small question... I can post code, table creation, etc... but I think this question can be able to be simply answered, if I explain it. If you want me to zip codes, etc... then just ask and I'll do it.

    Here it goes:

    I have a set up merge statement, and I have two columns. One is named ADD_DT, and the other is called LST_UPD_DT.

    Update in the merge statement, the LST_UPD_DT column is updated with the SYSDATE.
    When it is inserted in the merge statement, the ADD_DT column is updated with the SYSDATE.

    So, here is my question:

    Regardless of whether or not the information is updated, the LST_UPD_DT updates the SYSDATE every time. Any advice on how to update the LST_UPD_DT column only if information is changed/updated, so that the information is not changed would be not updated by the SYSDATE? I hope that this question was not too complicated.

    Thank you all and if you want to see the code or examples of table... Please ask and I'll post one. I just thought that this may be able to meet without it.

    Hello

    991769 wrote:
    OK, here's what the table looks like:

    Thank you.

    CREATE TABLE TBL_SUPPLIERS
    (
    SUPP_CD                 VARCHAR2(40 CHAR),
    SUPP_NM                 VARCHAR2(255 CHAR),
    ADD_DT                  VARCHAR2(50 CHAR),
    LST_UPD_DT              VARCHAR2(50 CHAR))
    

    Do not use a VARCHAR2 column for date information. Use a DATE column.

    CREATE TABLE D_SUPPLIERS
    (
    SUPP_CD                 VARCHAR2(40 CHAR),
    SUPP_NM                 VARCHAR2(255 CHAR))
    
    INSERT INTO TBL_SUPPLIERS VALUES (1234, MINING, '03-26-2013 3:33:49 PM', '04-02-2013 9:04:52 AM');
    INSERT INTO TBL_SUPPLIERS VALUES (2345, ELECTRIC, '03-26-2013 3:33:49 PM', '04-02-2013 9:04:52 AM');
    INSERT INTO TBL_SUPPLIERS VALUES (3456, COAL, '03-26-2013 3:33:49 PM', '04-02-2013 9:04:52 AM');
    

    You want people to view the solutions that actually work? Please make sure that your own instructions will actually work. Test and fix your code before posting.
    All INSERT statements you posted fail; You seem to be missing single quotes around string literals. I think you meant:

    INSERT INTO TBL_SUPPLIERS VALUES (1234, 'MINING', '03-26-2013 3:33:49 PM', '04-02-2013 9:04:52 AM');
    ...
    

    Here's one way:

    MERGE INTO  tbl_suppliers     sm
    USING  (
               SELECT  d.*
            FROM              d_suppliers        d
            LEFT OUTER JOIN  tbl_suppliers  t  ON  t.supp_cd  = d.supp_cd
            WHERE   t.supp_cd                            IS NULL
            OR        DECODE (t.supp_nm, d.supp_nm, 0, 1) = 1
           )                       ds
    ON     (sm.supp_cd = ds.supp_cd)
        WHEN MATCHED THEN
            UPDATE SET
                sm.supp_nm = ds.supp_nm,
                sm.lst_upd_dt = SYSDATE
        WHEN NOT MATCHED THEN
            INSERT (sm.supp_cd, sm.supp_nm, sm.add_dt)
            VALUES
            (ds.supp_cd, ds.supp_nm, SYSDATE);
    
    SELECT     *
    FROM     tbl_suppliers
    ORDER BY     SUPP_CD;
    

    This can be more efficient, because it does not generate redo, or triggers, when two tables have exactly the same line.

  • Why a State in MSO on a Page returns to the 1st State when she went from Portrait to landscape mode...

    My folio is Portrait and landscape and many of my pages have the MSO, and when I go back and forth between the layouts on my phone, the page returns to the State 1st in this MSO.

    Another major problem is that it takes 3-5 seconds to go from Portrait to landscape and vice versa.

    Folio is 25 version.

    I created all the pages in portrait first and then created a different layout (landscape).

    Any ideas?

    Thank you

    Make sure your portrait and landscape MSO have exactly the same name. InDesign changes the name of the ASM by adding a number when you make a copy of the WHO for a different layout. It will not solve the problem of return to the first State.

    Not sure on issues of speed, maybe tablet related?

    Good luck.

    JvR

  • Person registering in the Merge statement error!

    Is it possible to save indivudual error in the MERGE statement (Update / Insert).
    I'm unable to save these error. instead of MERGING, if I update the table in the cursor loop then I am able to record the individual error but the process takes time.
    Thanks in advance.
    Deba

    Hi Deba,

    Logging of DML errors:

    SQL> create table tab1 (x number(1));
    
    Table created.
    
    SQL> exec dbms_errlog.create_error_log('tab1')
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL> merge into tab1 t
      2        using (select 1 x from dual union all
      3               select 112 x from dual) s
      4  on (t.x = s.x)
      5  when not matched
      6  then insert (x) values (s.x)
      7  log errors into err$_tab1 reject limit unlimited;
    
    1 row merged.
    
    SQL>
    SQL> COL x for 9999
    SQL> select * from tab1;
    
        X
    -----
        1
    
    SQL> COL x for a4
    SQL> select ora_err_number$, X from err$_tab1;
    
    ORA_ERR_NUMBER$ X
    --------------- ----
               1438 112
    
    SQL>
    

    Concerning
    Peter

  • BlackBerry smartphones can not activate e-mail upon return to the United States

    I have a unlocked BB Torch which I have used successfully for international travel all summer, just to buy SIM cards in different countries.

    I returned yesterday to the United States and give my card AT & T SIM card in the phone.  Everything works (calls, texts, browser, BBM, Facebook, etc.)-with the exception of e-mail.  Nothing has pushed on the BB because I put the card in.

    I went to Setup-> e-mail-> activate account Email accounts and entered passwords for my two accounts (personal gmail and Google Apps work) but keep getting "sorry, cannot continue your session.  Please log in again. "Tried it more than 10 times with the same error message each time.

    Help.

    I had exactly the same question; If you're going to http://mobile.blackberry.com and select your region & carrier, you can then enter e-mail under the banner of connect, then select your email provider (or select other if they are not listed) and you can reconfirm your email account details. Once you have validated, your emails should start to come through, and you can then change your accounts through blackberry E-mail set up the application on the phone. I hope this helps!

  • RETURN TO THE UPDATE QUERY CLAUSE

    I have a request written in Postgres.   This will pick up the records in the table job_information with the State, as provided by the application (ex: "READY_TO_RUN") and with limit of records like the one provided by the application (ex: 100), then updates the job_information with app get (ex: "ACHIEVEMENTS") and returns that defined (means, returns the data table job_information total for these got put to date with the given State) records for the use of the application.

    Can someone give me advice on the translation in Oracle?   Thank you!!

    Query in Postgres

    UPDATE job_information AS J1
    SET status=?
    FROM
      (SELECT job_name,
        job_group,
        created_date
      FROM job_information
      WHERE status           =?
      AND CURRENT_TIMESTAMP >= scheduled_execution_time
      ORDER BY scheduled_execution_time limit ?
      ) AS J2
    WHERE J1.job_name   = J2.job_name
    AND J1.job_group    = J2.job_group
    AND J1.created_date = J2.created_date RETURNING *;
    

    Example of a query (in postgres):

    UPDATE job_information AS J1
    SET status= 'ACQUIRED'
    FROM
      (SELECT job_name,
        job_group,
        created_date
      FROM job_information
      WHERE status           = 'READY_TO_RUN'
      AND CURRENT_TIMESTAMP >= scheduled_execution_time
      ORDER BY scheduled_execution_time limit 100
      ) AS J2
    WHERE J1.job_name   = J2.job_name
    AND J1.job_group    = J2.job_group
    AND J1.created_date = J2.created_date RETURNING *;
    

    Oracle SQL - query, I wrote it is not working

    UPDATE JOB_INFORMATION SET STATUS=
    (
    WITH J2 as (
                            select job_name, job_group, created_date from (SELECT job_name, job_group, created_date FROM job_information WHERE status= :b and current_timestamp >= scheduled_execution_time order by scheduled_execution_time ) where rownum<= :c
                )
    SELECT distinct :a FROM JOB_INFORMATION J1, J2 WHERE J1.job_name = J2.job_name AND J1.job_group = J2.job_group AND J1.created_date = J2.created_date
    )
    RETURNING * FROM JOB_INFORMATION BULK COLLECT INTO SOMETHING ;
    
    1. create or replace package test_pack
    2. as
    3. type r_tab is (record
    4. test.job_name%type job_name,
    5. (status test.status%type);
    6. type t_tab is table of the r_tab;
    7. function test_func (v_status_o VARCHAR, v_status_i VARCHAR) - USE VARCHAR2
    8. T_tab RETURN PIPELINED;
    9. end;
    10. /
    11. create or replace the BODY of PACKAGE as test_pack
    12. function test_func (v_status_o VARCHAR2, v_status_i VARCHAR2) return t_tab pipelined as
    13. PRAGMA AUTONOMOUS_TRANSACTION;
    14. v_tab t_tab;
    15. Start
    16. Update test
    17. set status = v_status_o :-
    18. where Job_name in (select job_name TEST where status = :v_status_i).
    19. job_name, return STATUS
    20. bulk collect into v_tab;
    21. commit;
    22. because me in 1... loop v_tab. Count
    23. pipe row (v_tab (i));
    24. end loop;
    25. end;
    26. end;
    27. /

    REMOVE the colon before parameters and use the same types of data

  • need help with the Merge statement

    I'm on: Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

    I'm currently an UPDATE statement and then it works and is accurate, it takes 30 minutes. I heard that MERGE
    can do the same thing and is just as accurate and much faster!

    Here's the query I want to convert into a MERGE INTO statement. I tried to do it myself, but I get errors and don't know simply, since it's new for me.

    Basically I want to update table your on a corresponding condition in the table tt for 2 columns (GTP and UPDATE_DT), for UPDATE_DT I want to insert the Date current system.
    UPDATE /*+ PARALLEL (16) */  OLDER_Table ta
    
    SET (ta.GTP, ta.UPDATE_DT) = 
    
                    (SELECT /*+ PARALLEL (16) */ tt.GTP, SYSDATE
                     FROM NEWER_Table tt
                     WHERE ta.cust_id = tt.cust_id
                     AND ta.STAMP_DATE = tt.STAMP_DATE
                     AND ROWNUM = 1)
    
                     WHERE EXISTS (SELECT 1
                                   FROM NEWER_Table tt
                                   WHERE ta.cust_id = tt.cust_id
                                   AND ta.STAMP_DATE = tt.STAMP_DATE
                                   AND (NVL(ta.GTP, 'X') != NVL(tt.GTP, 'X'))); 
    Thank you!

    Hello

    Whenever you have a problem, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) of all of the tables involved.
    Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
    If you ask on a DML statement, such as UPDATE, CREATE TABLE and INSERT statements need to re - create the tables as they are before the DML, and results will be the content of the or the tables changed when it's all over.
    See the FAQ forum {message identifier: = 9360002}

    MERGE peut be much faster than update; Sometimes, there is no significant difference in speed.
    Tables in multiple situations like this, I've never seen a case where the MERGER has been slower than the UPDATE, even if the UPDATE is sometimes easier to code and just as fast.

    Maybe that's what you want:

    MERGE INTO  older_table            dst
    USING  (
               SELECT  n.cust_id
            ,        n.stamp_date
            ,        n.gtp
            ,        ROW_NUMBER () OVER ( PARTITION BY  n.cust_id
                                               ,           n.stamp_date
                             ORDER BY      n.gtp
                              )                    AS r_num
            FROM        newer_table  n
            JOIN        older_table     o  ON   n.cust_id     = o.cust_id
                                 AND     n.stamp_date     = o.stamp_date
                           AND     NVL ( n.gtp
                                    , 'X'
                                 )          != NVL ( o.gtp
                                                  , 'X'
                                              )
    
           )                 src
    ON     (    src.cust_id            = dst.cust_id
           AND  src.stamp_date     = dst.stamp_date
           AND  src.r_num            = 1
           )
    WHEN MATCHED THEN UPDATE
    SET    dst.gtp          = src.gtp
    ,      dst.update_date     = SYSDATE
    ;
    

    As I can't test it, I can't be sure.

  • ORA 22813 in the merge statement

    Hi the gems... Good afternoon...

    My version of the database is 11.2.0.1.0 Solaris 64-bit OS.

    I am facing a ' ORA-22813: value of the operand exceeds the limits of the system "during the execution of a procedure.
    I used loggers and found that it is getting failed in a MERGE statement.

    This merge statement is used to merge a table with a collection. the code is as 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<.....>
    Function GET_BALANCE_HIST (V_MERGE_REC) parameter is an array type.
    Now GET_BALANCE_HIST (V_MERGE_REC) is a function in the pipeline and we used that because the V_MERGE_REC collection can become huge with data.

    This process worked very well since the beginning, but since yesterday, it was constantly throwing 22813 ORA error in this line.

    Help, please... Thanks in advance...

    Gogol wrote:
    The code flow is as below:

    There is a sql query, the output is a set of some several lakes of records. Now we take the result of the sql query in a collection with a limit of 1000 (FETCH cur_sql COLLECT LOOSE v_balance_rec LIMIT 1000). Then we do a lot of processing, the calculation of this collection.

    After the treatment and calculation, we are filling another collection this collection transformed (V_BALANCE_REC) (V_MERGE_REC). Thus, if the loop iterates for 1000 times, then the V_MERGE_REC is filled with records of 1000 * 500 = 500000 processed.

    And then we go to this huge V_MERGE_REC collection as a parameter to this function.

    Don't know what are the Lakes. Please use International English.

    Why can't do you math in a SQL query?

    If it's really too hard to do in SQL (SQL queries can perform a treatment fairly complex), then I would look to Scripture
    results of a table and use it.

  • Unique constraint shot while refreshing in the MERGE statement.

    Hi guys

    I have a question that I can't solve. Would appreciate any help on this. The configuration of the data and the script is as below.
    SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 4 11:46:02 2011
    
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    
    SQL> 
    
    create table table_1
    (id number,
     id_name varchar2(20));
     
    Alter table table_1 add primary key(id);
    
    create table table_2
    (id number,
     id_name varchar2(20));
     
     insert into table_2 values (1, 'id_1');
     insert into table_2 values (2, 'id_2');
     insert into table_2 values (1, 'id_1_upd');
    
    SQL> select * from table_1;
    
    no rows selected
    
    SQL> select * from table_2;
    
            ID ID_NAME
    ---------- --------------------
             1 id_1
             2 id_2
             1 id_1_upd
    
    SQL> 
    
    SQL>  merge into table_1 target
      2   using (select id, 
      3                 id_name
      4            from table_2) source
      5   on (source.id = target.id)
      6   when matched then
      7      update set target.id_name = source.id_name
      8   when not matched then
      9      insert(id,
     10             id_name)
     11      values(source.id,
     12             source.id_name);
     merge into table_1 target
    *
    ERROR at line 1:
    ORA-00001: unique constraint (SYS_C00137508) violated
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  select constraint_type, table_name, status
      2*   from user_constraints where constraint_name = 'SYS_C00137508'
    SQL> /
    
    C TABLE_NAME                     STATUS
    - ------------------------------ --------
    P TABLE_1                        ENABLED
    Can someone help me please to solve this as the actual code that I am developing has the same configuration and I am constantly getting this error. As long as the same record does not come to the top in the 'source' table, MERGE performs an update or an insert.
    But as a "duplicate" coming soon to update, I get the error of unique constraint.

    Thank you
    -K.B.

    Dear Sir

    ERROR at line 1:
    ORA-00001: unique constraint (SYS_C00137508) violated
    

    You think two things

    (a) coherent reading: what was the situation of table_1 when the maching clause was initially assessed. There were 0 insert rows that correspond to which means that the merge operation will be all
    (b) your corresponding clause has a problem: the join column must be unique in both tables the case the merger will be ambiguous. You do not have a unique key on the source table
    (c) think that the merge operation will never insert id = 1 and then update id = 1 within the same operation. Will never happen

    Hope this helps

    Mohamed Houri

Maybe you are looking for