Problem with merge using package (row)variable

We're doing an ETL project, where we have to validate data coming from staging tables before inserting / updating them in our data tables.
We use a validate function for this, in which we 'test' our mappings and business logic, and returns 'OK' if no errors were occured.This function is called in the WHERE clause, and populates a package row variable. From this variable, values are read in the insert / update statement, using a get function.
The problem is that sometimes, with a data set with NO duplicate keys, we get an ORA-00001 error, and sometimes not.
Does anyone have any idea why this error could occur ? We're on Oracle 9.2.0.5.0.
For the demo mentioned below, the following statement fails , while it succeeds if we add 'and rownum < 11' to the where clause :
merge into target_tab t
using (select st.* from source_tab st where demo_pack.assign_var(st.attrib_1, st.attrib_2, st.attrib_3) = 'OK') s
on (t.attrib_1 = s.attrib_1 and
t.attrib_2 = s.attrib_2)
when matched then update
set t.attrib_3 = demo_pack.get_attrib('ATTRIB_3')
when not matched then
insert(attrib_1, attrib_2, attrib_3)
values (demo_pack.get_attrib('ATTRIB_1'), demo_pack.get_attrib('ATTRIB_2'), demo_pack.get_attrib('ATTRIB_3'));
Can anyone explain to me why this statement sometimes fails, and other times not ?
Thanks in advance .
demo tables / packages :
create table source_tab
attrib_1 varchar2(30),
attrib_2 varchar2(30),
attrib_3 varchar2(200)
create table target_tab
attrib_1 varchar2(30) not null,
attrib_2 varchar2(30) not null,
attrib_3 varchar2(200),
constraint pk_target_tab primary key(attrib_1, attrib_2)
insert into source_tab
select table_name, column_name, data_type
from user_tab_columns;
commit;
create or replace package demo_pack as
function assign_var(p_attrib_1 in target_tab.attrib_1%type,
p_attrib_2 in target_tab.attrib_2%type,
p_attrib_3 in target_tab.attrib_3%type) return varchar2;
function get_attrib(p_name in varchar2) return varchar2;
end;
create or replace package body demo_pack as
g_rec target_tab%rowtype;
function assign_var(p_attrib_1 in target_tab.attrib_1%type,
p_attrib_2 in target_tab.attrib_2%type,
p_attrib_3 in target_tab.attrib_3%type) return varchar2 is
begin
g_rec.attrib_1 := p_attrib_1;
g_rec.attrib_2 := p_attrib_2;
g_rec.attrib_3 := p_attrib_3;
return 'OK';
end;
function get_attrib(p_name in varchar2) return varchar2 is
l_return varchar2(200);
begin
if p_name = 'ATTRIB_1' then
l_return := g_rec.attrib_1;
elsif p_name = 'ATTRIB_2' then
l_return := g_rec.attrib_2;
elsif p_name = 'ATTRIB_3' then
l_return := g_rec.attrib_3;
end if;
return l_return;
end;
end;
/

It's not necessarily that the problem is within your package code. As long as UNIQUE constraint exists on DEST table, any MERGE statement may fail with ORA-00001 due to concurrent updates and inserts taking place.
Of course, it's just my guess but consider the following scenario (three sessions modify DEST table in parallel – and to keep this example clear, I put their commands in chronological order):
S#1>  create table dest(x primary key, y) as
  2   select rownum, rownum
  3     from dual
  4  connect by level <= 5;
Table created.
S#1>  create table src(x, y) as
  2   select rownum + 1, rownum + 1
  3     from dual
  4  connect by level <= 5;
Table created.
S#1> select * from src;
         X          Y
         2          2
         3          3
         4          4
         5          5
         6          6
S#1> select * from dest;
         X          Y
         1          1
         2          2
         3          3
         4          4
         5          5
S#2> -- Now, session #2 will update one row in DEST table
S#2> update dest
  2     set y = 40
  3   where x = 4;
1 row updated.
S#2> select * from dest;
         X          Y
         1          1
         2          2
         3          3
         4         40
         5          5
S#1> -- Session #1 issues the following MERGE:
S#1> merge into dest d
  2  using (select * from src) s
  3     on (s.x = d.x)
  4   when matched then update set d.y = s.y
  5   when not matched then insert (d.x, d.y)
  6        values (s.x, s.y);
-- At this point, session #1 becomes blocked as it can not modify row locked by session #2
S#3> -- Now, session #3 inserts new row into DEST and commits.
S#3> -- MERGE in session #1 is still blocked.
S#3> insert into dest values (6, 6);
1 row created.
S#3> select * from dest;
         X          Y
         1          1
         2          2
         3          3
         4          4
         5          5
         6          6
6 rows selected.
S#3> commit;
Commit complete.
S#2> -- Session #2 rolls back its UPDATE.
S#2> rollback;
Rollback complete.
-- Finally, session #1 is getting unblocked, but...
merge into dest d
ERROR at line 1:
ORA-00001: unique constraint (MAX.SYS_C0032125) violated
S#1>Hope this helps,
Andrew.

Similar Messages

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

  • Has anyone else had problem with the STANDARD package?

    Hi Oracle gurus, has anyone here had the same problem with the STANDARD package? Or do I have to reinstall Oracle to make it work?
    Thanks.
    Ben

    missesboggs wrote:
    I literally just called AT&T and Apple about this today.  I was having issues with iMessage and texting my husband.  His texts back to me would show up as my name.  Turns out it's because we share the same AppleID.  So, I'm currently trying to change mine, but it hasn't worked so far.  I'm on hold with Apple right now to see if I can get it fixed.
    Both of you have registered the same email address for iMessage. If you were using a shared Apple ID and you updated your phones to iOS5, the default will be the Apple ID. Go into settings and change it.

  • Problem with procedure in package

    Problem with procedure in package:
    create table accounts
    (acno number(10),
    name varchar2(20),
    balance number(10,2));
    create package banking is
    procedure new_acct(acno NUMBER, name IN VARCHAR);
    procedure acct_dep(acno IN NUMBER, amount IN NUMBER);
    procedure acc_wdr(acno IN NUMBER, amount IN NUMBER);
    procedure acc_bal(acno IN NUMBER, bal OUT NUMBER);
    function acc_drwn(acno IN NUMBER) RETURN BOOLEAN;
    end banking;
    create or replace package body banking is
    procedure new_acct ( acno IN number,
    name IN varchar) is
    begin
    insert into accounts
    (acno, name, balance)
    values
    (acno, name,0);
    end;
    procedure acct_dep(acno IN NUMBER,
    amount IN NUMBER) is
    begin
    update accounts
    set balance = balance + amount
    where acno = acno;
    end;
    procedure acc_wdr(acno IN NUMBER,
    amount IN NUMBER) is
    begin
    update accounts
    set balance = balance - amount
    where acno = acno;
    end;
    procedure acc_bal(acno IN NUMBER,
    bal OUT NUMBER) is
    begin
    declare cursor c_balance(i_acno IN accounts.acno%type) is
    select balance
    from accounts
    where acno = i_acno;
    acc_bal accounts.balance%type;
    begin
    if c_balance%isopen then
    close c_balance;
    end if;
    open c_balance(acno);
    fetch c_balance into acc_bal;
    close c_balance;
    end;
    end;
    function acc_drwn(acno IN NUMBER) RETURN BOOLEAN is
    begin
    declare cursor c_balance(i_acno IN accounts.acno%type) is
    select balance
    from accounts
    where acno = i_acno;
    bal accounts.balance%type;
    begin
    if c_balance%isopen then
    close c_balance;
    end if;
    open c_balance(acno);
    fetch c_balance into bal;
    close c_balance;
    if bal < 0 then
    return true;
    else
    return false;
    end if;
    end;
    end;
    end banking;
    begin
    banking.new_acct(123,'FRANKS');
    end;
    execute banking.acct_dep(123,100);
    execute banking.acc_wdr(123,50);
    Works fine up to this point, however when running the balance check the balance amount is not visible?
    SQL> set serveroutput on
    SQL> begin
    2 declare
    3 bal accounts.balance%type;
    4 begin
    5 banking.acc_bal(123,bal);
    6 dbms_output.put_line('Franks balance is '||bal);
    7 end;
    8 end;
    9 /

    procedure acc_bal(acno IN NUMBER,
       bal OUT NUMBER)
    is
    cursor c_balance(i_acno IN accounts.acno%type) is
       select balance
       from accounts
       where acno = i_acno;
       l_acc_bal accounts.balance%type;
    begin
       open c_balance(acno);
       fetch c_balance into l_acc_bal;
       close c_balance;
       bal := l_acc_bal;
    end;

  • Has anybody had the following error while trying to download iTunes 10.5? There is a problem with Windows Installer package. A program required for this install to complete could not be run.

    Has anybody had the following error while trying to download iTunes 10.5? There is a problem with Windows Installer package. A program required for this install to complete could not be run.

    Go to "control panel" then "add or remove programs".  Highlight "Apple software update"  Choose "change" click "Repair"  This should do the trick.  Then download and install iTunes 10.5 again.

  • Tried to install iTunes 10.5 this morning but an error appeared saying "problem with windows installer package. A program required for this install to complete could not be run." Can someone please help

    I tried to install iTunes 10.5 this morning but an error appeared saying "problem with windows installer package. A program required for this install to complete could not be run." Can someone please help

    Firstly, are you installing iTunes for the first time or are you updating your current version of iTunes?
    If you're installing iTunes for the first time have you tried redownloading the installer package? Perhaps the file you downloaded originally is corrupted...
    http://www.apple.com/itunes/
    If you've tried that, then try installing iTunes as your computer's administrator. To do this right-click the install package and choose "Run as administrator".
    If you're updating iTunes to the most recent version try repairing the Apple Software Update program on your computer. It's under the add/remove programs.
    1. Open the control panel
    2. Open Add/Remove programs (called "Programs and Features" in Windows 7)
    3. Navigate to "Apple Software Update" in the list and click on it
    4. Click on "Change" then select "Repair" (or just select the repair option in Windows 7)
    Once you repair this, try running iTunes and the update again.
    Fingers crossed!

  • HT1349 Hi all,I have just purchased new iphone but have difficulty in completing the itunes download with message : problem with Windows installer package. A program run as part of the setup did not finish as expected.

    Hi all,I have just purchased new iphone but have difficulty in completing the itunes download with message : problem with Windows installer package. A program run as part of the setup did not finish as expected.
    Would appreciate help...its driving me up the wall!!

    Perhaps let's first try updating your Apple Software Update.
    Launch Apple Software Update ("Start > All Programs > Apple Software Update"). Does it launch and offer you a newer version of Apple Software Update? If so, choose to install just that update to Apple Software Update. (Deselect any other software offered at the same time.)
    If the ASU update goes through okay, try another iTunes install. Does it go through without the errors this time?

  • Having trouble trying to install itunes 10.5. Receive message saying 'There is a problem with this installer package. A program required for this install to complete could not be found. Please contact product vendor'

    Having trouble trying to install itunes 10.5. Receive message saying 'There is a problem with this installer package. A program required for this install to complete could not be found. Please contact product vendor'

    Managed to get the installation sorted. Go to Control Panel, and where you have a list of all installed programs, repair all the Apple/Itunes related programs. Installation worked fine after that. Hopefully it helps you out too!

  • Problem with BAPI_CUSTOMER_CREATEFROMDATA1 using JCo on IDES

    sorry, wrong board - i opened a new post
    Problem with BAPI_CUSTOMER_CREATEFROMDATA1 using JCo on IDES
    Hello everyone,
    we are working on a student project and would like to create customers (debtors) in an SAP IDES system.
    Using the ref-customer to copy from, and some personal-data below, we get the error message
    'Internal error: External no.assignment for reference customer/customer'
    We also tried with BAPI_CUSTOMER_GETINTNUMBER, and ACCOUNTGROUP ZINT (New Internet Customer, others won't work?). But CREATEFROMDATA1 takes no CustomerNo created this way, nor it wants to create one 'internal'?
    Any suggestions? Thanks a lot for your help,
    Greetings,
    Tobias Schmidbauer
              inParams = function.getImportParameterList().getStructure(
                   "PI_COPYREFERENCE");
              inParams.setValue("0000001000", "REF_CUSTMR");
              inParams.setValue("1000", "SALESORG");
              inParams.setValue("10", "DISTR_CHAN");
              inParams.setValue("00", "DIVISION");
              inParams =function.getImportParameterList().getStructure(
                   "PI_PERSONALDATA");
              inParams.setValue("Simpson", "LASTNAME");
              inParams.setValue("Homer", "FIRSTNAME");
              inParams.setValue("Jay","MIDDLENAME");
              inParams.setValue("Springfield", "CITY");
              inParams.setValue("DE", "LANGU_P");
              inParams.setValue("DE", "LANGUP_ISO");
              inParams.setValue("DE", "COUNTRY");
              inParams.setValue("EUR", "CURRENCY");
              inParams.setValue("12345", "POSTL_COD1");
    Message was edited by: Tobias Schmidbauer

    Hello Brian,
    Thanks for your pointer. Actually The customer's reference number i was providing in the PI_COPYREFERENCE structure was a sold-to party customer and it uses external customer number assignment. When i used "New Internet Customer" (that doesnt use external assignment by default) as customer's account group, the customer was created successfully and assigned customer number was returned.
    I want to ask now how could we give a customer number in the BAPI as i am unable to find any such column in any of the tables. (Customer number is an "out" parameter so it can only return the number of created customer). Secondly, how to chnage the external assignment property of a particular account group (like sold-to party). i.e, how could we change the account group configurations through SAP GUI??
    - Umair

  • Problems with Merging Account

    Hi Experts,
    I have 2 problems with merging accounts:
    1) Opportunity is not moved from source data to master data. I do not know why. Central BP is changable.
    2) Contact Person is only copied, not moved. This causes problems later on when we want to delete the source data.
    Any idea how to solve this?
    Best regards,
    Cristina

    Hi Arno:
    First of all: Thanks for answering my thread!
    The problem with opportunities in my system is, that they are not merged at all, not even with the batch job. I checked trx. BUSWU02. Node CRM370 is assigned to variant CLEAR_REP.
    Also the central Business Partner in opportunity remains changable, once the opportunity was saved.
    Anything else I have to check??
    Best regards,
    Cristina

  • HT1926 (iTunes) Problem with Windows installer package?

    (iTunes) Problem with Windows installer package?  I try to install the new version of iTunes but get an error "Problem with Windows installer package.  A Program required for this install could not be run."  Can anyone help shed some light for me as to how to correct this?  I have tried to install the program through Chrome, Explorer and FireFox but have had no success.  I have included a screenshot of the error.  Hopefully it's visable.  Thank you for any help.

    Found answer for anyone else curious.  I love the apple community.  Thanks guys for help!
    https://discussions.apple.com/docs/DOC-3551

  • Trouble with itunes upgrade I receive an error message problem with windows installer package

    I am trying to upgrade itunes.  I am running windows vista 64.  Everytime I try to upgrade I get an error that says Problem with windows installer package.  Anyone know how to fix this?

    No drivers in LowerFilters.
    No drivers in UpperFilters.
    Failed loading CD / DVD drives, error -43. Try doing a repair install on iTunes from the “Add or Remove Programs” control panel.
    I'd start with the following document, with one modification. At step 12 after typing GEARAspiWDM press the Enter/Return key once prior to clicking OK. (Pressing Return adds a carriage return in the field and is important.)
    iTunes for Windows: "Registry settings" warning when opening iTunes

  • Why is itunes saying "there is a problem with this installer package. a program required for this install to complete could not be run. contact your support personnel or package vendor."

    why is itunes saying "there is a problem with this installer package. a program required for this install to complete could not be run. contact your support personnel or package vendor."

    Go to START > ALL PROGRAMS > Apple Software Update. If it offers you a newer version of Apple Software Update, do it but Deselect any other software offered at the same time. Once done, try another iTunes install
    If you can't find ASU, go to Control Panel:
    XP - Add n Remove Programs
    Win7/Vista - Programs n Features
    Highlight ASU, click change then Repair.

  • Problem with attachment using SO_NEW_DOCUMENT_ATT_SEND_API1

    Hi,
    I'm using function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send emails from SAP (to Outlook - but the problem can already be observed when checking the email attachment in transaction SOST) with attachments.
    My attachment is a tab delimited file (so that I can open with MS Excel) with a line size of approx. 1600 characters. I mean, concatenating all fields of the output table into a 1600 character field, separated by tabstops (cl_abap_char_utilities=>horizontal_tab)
    I am using function module SCMS_STRING_TO_FTEXT to convert the internal table that I want to send to the line size as accepted by function module SO_NEW_DOCUMENT_ATT_SEND_API1, tables parameter contents_bin. Due to function module SCMS_STRING_TO_FTEXT this happens line by line, using a string variable. I make sure to remove any exess blanks that appear in the process due to not completey filled character fields. And for all rows bar the first the string is prefixed with (cl_abap_char_utilities=>cr_lf). I believe that's required so that SAP knows to put the lines back together. So far so good.
    When checking the email's attachment via SOST (and the same happens in Outlook) there are extra blanks in certain fields. Like:
    Annual Base
    92,928.         00
    or
    Email
    First L ast
    In debugging it appears that these excess spaces (sometimes 1, sometimes several) appear where the 1600 character data line is split into the 255 character pieces in 'contents_bin'. But then it happens quite randomly and cannot be observed in all data rows.
    Is there a better way of splitting my internal table into 255 character chunks so that what is one field will never get split up into two rows. For the above example, the two fields would show like this in contents_bin
    ....  92,928.        
    00
    and
    First_L
    ast
    Or where else lies the problem?
    Thanks in advance!
    Philipp

    Ron,
    Thank you for the suggestion. Just tried but issue remains exactly the same. The function module you have suggested builds the table in the same way.
    But, after a few more rounds of debugging and scratching my head it occured to me that my problem is self inflicted. I was using the condense statement in an attempt to get rid of the trailing blanks at the end of a row causing the last column to be filled with lots of spaces at the end. But it wasn't working anyway and I have since inserted a dummy column at the end to take all those trailing blanks. What this condense statement did though was creating trailing blanks in some of those rows with 255 characters fixed length and those trailing blanks then showed up as additional blanks in some columns in the attachment that the emailing function module created by putting those lines back to it's original length of close to 1600 characters.
    Problem solved!
    Regards,
    Philipp

  • Some problems with af:table (new rows with presetting and autosubmit)

    Hi, I'm working with an af:table, but I'm having some troubles.
    Background:
    Jdev 11.1.1.5.0
    Firefox 6.0.2
    In the Bounded Task flow:
    ExecuteWithParams -> fragment < commit/rollback
    ExecuteWithParams: Set a bind variable with a value from bpm payload for get only rows with that value.
    In the fragment:
    An af:table with a button CreateInsert (the new rows need to use the value of the payload in the hidden column, i don't know how do this, assign the value to the #{row.bindings.IdDistribution.inputValue}) [First problem]
    The inputText of the af:table has the autoSubmit in true. The first time that I fill the cells I got this error in each entered value, after press the tab key.
    ADF-FACES- 60097... ADF_FACES-60096:Server Exception during PPR, #n (where n is 1,2,3,4 for each cell). [Second problem]
    When I press the Commit Button, all values from cells dissapears. And I got the message from validator that cells can't be null. [Third problem]
    If I fill cells again, all work right. Validations, no errors ADF_FACES-60096 and a successful commit.
    How I can solve these problems?
    Thanks in advance.

    Hi,
    you need to bind the value property of the selectOneRadio to the row variable. Say the button updates an attribute "q1" then the value property should point to #{row.bindings.q1.inputValue} assuming you use ADF and ADF BC. The question svary I assume., so you need to query thequestion for each row. For this reference a managed bean doe the f:selectItems and in the managed bean use the #{row} attribute to get a hold of the current rendered row (instance of JUCtrlHierNodeBinding if ADF is used. This has a method getRow() to obtain the Row object). The list then returns the answers to select from
    Frank

Maybe you are looking for

  • How to take one apple ID that has been shared and create a new one for my daughter.

    When I first got my daughter an ipod years ago, I had it registered with my apple ID. She just got a macbook and all of my contacts, text, etc have downloaded to her computer.  She obviously needs her own apple ID but I don't know how to start the pr

  • Can't compile - URGENT

    hi. hope someone can help. this is important, it's for my coursework at uni. I have downloaded the new java 1.4.1_01 and installed. i set the paths in my IDE to it, everything great, but if I compile, it says: "Registry key 'Software\JavaSoft\Java Ru

  • How to escape or remove the special characters in the xml element by regula

    Hi members, How to escape or remove the special characters in the xml element by regular expression  in java?? For Example , <my:name> aaaa </my:name> <my:age> 27 </my:age> In the above example , i have to retrieve the value of the <my:name> Element(

  • PSE9: renaming of folders in organizer very slow

    My problem: when renaming folders in the folder tree in PSE 9's organizer, it takes a long time for the name change to happen. It's easily 10-20 seconds. Is this a known phenomenon? Has anybody made the same observation (and found a solution?) Comput

  • Zfs and encryption

    we are looking for a filesystem level encryption technology. At this point most of our services are on zfs. At one time I saw encryption on the roadmap for zfs features. Where does this sit now? Are there test bed versions of opensolaris where we can