Updating lookup table using merge query

Hi Experts,
My requirement is, we have total 4 tables called x,y,z and a_lookup table. join column between all these tables is deptno.
I need to update a_lookup table based on below conditions
   condition1 :   Update a_lookup table with matched records of X and Y
   condition2:    If there is any record in X is not matching with Y, then we need to compare with Z and update the a_lookup table accordingly
Here is the table scripts and my attempt as well.
Only doubt is,  is my MERGE statement looks fine or is there any other better way to update the a_lookup table ?
Please share your thoughts on this.
create table x(empno number, deptno number);
  -- sample data
  insert into x
    select level, level * 10 from dual connect by level <= 10;
  create table y(empno number, deptno number);
  -- sample data
  insert into y
    select level, level * 10 from dual connect by level <= 5;
  create table z(empno number, deptno number);
  -- sample data
  insert into z
    select level, level * 10 from dual connect by level <= 10;
  create table a_lookup(empno number, deptno_lookup number);
  -- sample data
  insert into a_lookup
    select null, level * 10 from dual connect by level <= 10;
  -- Merging records into a_lookup based on X,Y,Z. Used right outer join on X and Y
merge into a_lookup a
using ( (select  x.deptno,x.empno   from x,y where x.deptno=y.deptno)
           union all
           (select z.deptno,z.empno from z, (select x.deptno from x,y where x.deptno=y.deptno and y.deptno is null)  res1
              where z.deptno = res1.deptno)
           ) res
on( a.deptno_lookup = res.deptno)
when matched then
  update set a.empno = res.empno;
Cheers,
Suri ;-)

Assuming empno is unique in X, Y and Z:
merge
  into a_lookup a
  using (
         select  nvl(y.empno,z.empno) empno,
                 x.deptno
           from  x,
                 y,
                 z
           where y.deptno(+) = x.deptno
             and z.deptno(+) = x.deptno
        ) b
  on (
          a.deptno_lookup = b.deptno
      and
          b.empno is not null
  when matched
    then
      update
         set a.empno = b.empno
10 rows merged.
SCOTT@orcl > select * from a_lookup;
     EMPNO DEPTNO_LOOKUP
         1            10
         2            20
         3            30
         4            40
         5            50
         6            60
         7            70
         8            80
         9            90
        10           100
10 rows selected.
SCOTT@orcl >
SY.

Similar Messages

  • Code to update a table using sqlldr

    Hi all,
    can anybody give the code to update a table using sqlldr with an example
    thank you

    You want add the new line and modified the existing line (based on empno) from file e:\scripts\sql\emp2_ext.dat into table emp2 :
    7782,CLARK,MANAGER,7839,09/06/81,80000,,10
    8000,ORACLE,DATABASE,,11/02/07,99999,,20Then :
    SQL> conn system/mypwd
    Connected.
    SQL>
    SQL> create directory my_dir as 'e:\scripts\sql';
    Directory created.
    SQL>
    SQL> grant read,write on directory my_dir to scott;
    Grant succeeded.
    SQL>
    SQL> conn scott/mypwd
    Connected.
    SQL> create table emp2_ext
      2  (EMPNO    NUMBER(4),
      3   ENAME    VARCHAR2(10),
      4   JOB      VARCHAR2(9),
      5   MGR      NUMBER(4),
      6   HIREDATE DATE,
      7   SAL      NUMBER(7,2),
      8   COMM     NUMBER(7,2),
      9   DEPTNO   NUMBER(2)
    10  )     
    11  ORGANIZATION EXTERNAL
    12  ( TYPE ORACLE_LOADER
    13    DEFAULT DIRECTORY my_dir
    14    ACCESS PARAMETERS
    15    ( records delimited by newline
    16      badfile my_dir:'emp2_ext.bad'
    17      logfile my_dir:'emp2_ext.log'
    18      fields terminated by ','
    19      missing field values are null
    20      ( empno, ename, job, mgr, hiredate char date_format date mask "dd/mm/yy",
    21        sal, comm, deptno
    22      )
    23    ) LOCATION ('emp2_ext.dat')
    24  ) ;
    Table created.
    SQL>
    SQL> select * from emp2_ext;
         EMPNO ENAME      JOB              MGR HIREDATE        SAL       COMM     DEPTNO
          7782 CLARK      MANAGER         7839 09/06/81      80000                    10
          8000 ORACLE     DATABASE             11/02/07      99999                    20
    SQL> select * from emp2;
         EMPNO ENAME      JOB              MGR HIREDATE        SAL       COMM     DEPTNO
          7782 CLARK      MANAGER         7839 09/06/81      24500                    10
          7839 KING       PRESIDENT            17/11/81      50000                    10
          7934 MILLER     CLERK           7782 23/01/82      13000                    10
    SQL> merge into emp2 a
      2  using (select * from emp2_ext) b
      3  on    (a.empno=b.empno)
      4  when matched then update set a.ename=b.ename,
      5                               a.job=b.job,
      6                               a.mgr=b.mgr,
      7                               a.hiredate=b.hiredate,
      8                               a.sal=b.sal,
      9                               a.comm=b.comm,
    10                               a.deptno=b.deptno
    11  when not matched then insert (a.empno, a.ename, a.job, a.mgr, a.hiredate, a.sal, a.comm, a.deptno)
    12                        values (b.empno, b.ename, b.job, b.mgr, b.hiredate, b.sal, b.comm, b.deptno);
    2 rows merged.
    SQL>
    SQL> select * from emp2;
         EMPNO ENAME      JOB              MGR HIREDATE        SAL       COMM     DEPTNO
          7782 CLARK      MANAGER         7839 09/06/81      80000                    10 --modified line
          7839 KING       PRESIDENT            17/11/81      50000                    10
          7934 MILLER     CLERK           7782 23/01/82      13000                    10
          8000 ORACLE     DATABASE             11/02/07      99999                    20 --added line
    SQL> HTH,
    Nicolas.
    Well, Hans has already give good explanation with docs links...
    Message was edited by:
    N. Gasparotto

  • How to Update  crmd_customer_h TABLE Using CRMV_EVENT Through Funtion Module

    Hi
    How we can update customer_h table using the CRMV_EVENT Where i implemented logic below in the Funtion Module.
    data:     lt_doc_flow          TYPE crmt_doc_flow_wrkt,
              lw_cust_h_com        TYPE crmt_customer_h_com,
              lw_input_field_names TYPE crmt_input_field_names,
              lt_input_field_names TYPE crmt_input_field_names_tab,
              lt_objects_to_save TYPE crmt_object_guid_tab,
              lw_guid TYPE CRMT_OBJECT_GUID.
    DATA : lv_process_type TYPE crmt_process_type.
    data: wa_doc_flow type CRMT_DOC_FLOW_WRK.
    data: wa_customer_h type crmd_customer_h.
    *  Function module for retriving the Process type.
      CALL FUNCTION 'CRM_ORDERADM_H_READ_OW'
        EXPORTING
          iv_orderadm_h_guid     = iv_header_guid
        IMPORTING
          ev_process_type        = lv_process_type
        EXCEPTIONS
          admin_header_not_found = 1
          OTHERS                 = 2.
    if lv_process_type eq 'ZG01'.
    CALL FUNCTION 'CRM_DOC_FLOW_READ_OB'
    EXPORTING
       IV_HEADER_GUID                 = iv_header_guid
    IMPORTING
       ET_DOC_FLOW_WRK                = lt_doc_flow.
    read table lt_doc_flow with key objtype_a = 'BUS2000116' INTO wa_doc_flow. "gc_object_type-service.
                if sy-subrc eq 0.                    "set flag for service order
                lw_cust_h_com-ref_guid       =  wa_doc_flow-objkey_a.
                lw_cust_h_com-ZZTRAIL_FLAG   = 'X'.
                 lw_cust_h_com-mode           = 'A'.
                lw_cust_h_com-ref_handle     = '0000000001'.
                lw_guid = wa_doc_flow-objkey_a.
                INSERT lw_guid INTO TABLE lt_objects_to_save.
         endif.
                  lw_input_field_names-fieldname = 'REF_GUID'.
                lw_input_field_names-fieldname = 'ZZTRAIL_FLAG'.
              lw_input_field_names-changeable = ' '.
               INSERT lw_input_field_names INTO TABLE lt_input_field_names.
    Maintain Customer H
             CALL FUNCTION 'CRM_CUSTOMER_H_MAINTAIN_OW'
                  EXPORTING
                    is_customer_h_com    = lw_cust_h_com
                  CHANGING
                    ct_input_field_names = lt_input_field_names
                  EXCEPTIONS
                    header_change_error  = 1
                    header_create_error  = 2
                   error_occurred       = 3.
    ENDIF.
    *endif.
    *Clearing local variables
      clear: lv_process_type,
             lw_cust_h_com,
             lw_input_field_names.
    *Free internal tables
      free: lt_doc_flow,
            lt_input_field_names.

    Hi Faisal
    I think your not clear with what i am saying anyhow i will again explain you my requirement
    As per my requirement
    1)in the service order search report i need to add a field called "Has trail order with No Follow up" with values "Yes" & "Blank"
    For above Field i added  using the structure CRMST_QUERY_SRVO_BTIL and through configuration i am able to display the field in webui as per (Attachement Pic 1)
    2)When i  search with search criteria as  "Has trail order with No Follow up" with  "Yes"
    Then in result list i need to show the service order those having follow up as trail orders(sales order) only.if for  next document trail order  having any follow up then those service orders dont want to show in result list.
    For above requirement i implemented F.M using CRMV_EVENT & I configured for BUS2000115 And BEFORE_SAVE The Order
    The FM Will get trigger when i save the service order and for that service order if create any follow up and try to save the trail order then This FM Will trigger and in this i am doing validations.
    3)Add one AET Trail Flag field is added under CUSTOMER_H Table.
    4)in the FM I am validating for if the trail order having the preceding document as service order then i need to make flag as "X" For that service order in customer_h
    if suppose when i delete trail order from the service order then that flag must need to be "unset" from the CUSTOMER_H.
    Why bcoz we are doing above process is do show records in result list based on Flag values
    these flag checks are validating in the BADI Which we implemented for search logic.
    Please refer below Login for my requirement:-
    Proposal to have a custom “flag” field (background at table level,
         crmd_customer_h) linked to service order which gets flagged whenever at
         least one Trial order is created and saved from the Service Order.
    The flag value should be cleared when all the trial orders created and
    saved as follow up transactions are deleted from the system.
    Similarly for Trial Orders will use the same custom “flag” field
         which gets activated when at least one follow up is created and saved from Trial Order.
    The flag value should be cleared when all the follow up transactions from
    the Trial Order are deleted from the system.
    When the above search criteria “Has Trial order with no follow up”
         “is” “Yes” is applied then the logic derives all the service
         orders which satisfy additional search criteria applied in the search and
         for these Service orders checks if the custom flag field is checked to
         derive all Service orders which have Trial order. The custom flag values
         values are derived from crmd_customer_h table in CRM.
    4 )Further for all the Trial Orders determined in Step 3
    check if the Trial Order has a follow up by checking if the custom flag field
    is checked. The custom flag values are derived from crmd_customer_h table in
    CRM.
    5) If step 4 is not met populate the preceding Service
    Orders in the Result list

  • How can I find number of columns in a table using a query

    Hi
    I want to find the number of columns in a table using a query.
    Any help in this regard is much appreciated.
    Cheers

    Hi,
    This is the output i get when i executed ur query
    OWNER     OBJECT_NAME     OBJECT_TYPE
    SMLDBO     T2311_SURVEY_QUESTIONS     TABLE
    select OWNER,OBJECT_NAME,OBJECT_TYPE
    from all_objects
    where OBJECT_NAME = 'T2311_SURVEY_QUESTIONS';
    works Fine.
    But if i use the below query it returns : 0
    SELECT count(*) FROM user_tab_columns
    WHERE table_name =upper( 'T2311_SURVEY_QUESTIONS');
    What could be problem.
    The table exists + name of the table is correct + it resides in my schema itself.
    Any guess !!!

  • Updating EKKO table using E1BPPAREX

    Hi all,
    My requirement is to update ekko table using E1BPPAREX segement. I have gone through so many posts regarding this.
    In my case, PO number is not yet created. I am using BAPI_PO_CREATE1 for creating this . From PI side, if they pass the custom field value in the appropriate postion of VALUEPART field of E1BPPAREX, will it get updated to the ekko table automatically.
    Regards,
    Sajith

    Hi Sajith,
      you have to do is populate structure extensionin. You'll have to implement the fm DDIF_NAMETAB_GET to look for the right place (offset) in order to add the field on the structure extension in.
    Example:
      CALL FUNCTION 'DDIF_NAMETAB_GET'
        EXPORTING
          tabname   = c_ext_table   --> ''BAPI_TE_MEPOHEADER
        TABLES
          dfies_tab = lt_tab
        EXCEPTIONS
          not_found = 1
          OTHERS    = 2.
      CLEAR l_offset.
      LOOP AT lt_tab.
        CASE lt_tab-fieldname.
          WHEN c_yourfield.
            w_extin-valuepart1+l_offset = p_yourfield.
        ENDCASE.
        ADD lt_tab-leng TO l_offset.
      ENDLOOP.
      MOVE c_ext_table TO w_extin-structure.
      APPEND w_extin TO p_i_extin.
    Regards,
    Carlos.

  • Updating multiple tables using JDBC Adapter

    Hi,
    I am trying to insert/update multiple tables using one message via JDBC adapter. The following is the message being posted. However, only the first statement was executed. Anything wrong?
    Thanks in advance!
    Hart
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:DeliveryDBUpdate xmlns:ns0="http://test.com/r3_integration"><DeliveryData><DelHeader action="UPDATE_INSERT"><table>DelHeader</table><access><DelNo>0080000230</DelNo><DelType>LF</DelType><XOverwrite>X</XOverwrite><ShipTo>0000000026</ShipTo><SoldTo>0000000026</SoldTo><Priority>00</Priority><DocDate>02/17/2007</DocDate><GText>CIF Test</GText><DelDate>02/20/2007</DelDate><PickDate>02/20/2007</PickDate><ShipPoint>NO02</ShipPoint><PackCount>00000</PackCount></access><key><DelNo>0080000230</DelNo></key></DelHeader>
    <DelItem action="INSERT"><table>DelItem</table><access><DelNo>0080000230</DelNo><ItemNo>000010</ItemNo><GText>10# GRAN-GREAT VALUE</GText><Material>G04410G611</Material><Plant>6005</Plant><SLoc>6005</SLoc><RefDoc>mmenon32</RefDoc><RefItem>00000000</RefItem><DelQty>5.000</DelQty><UOM>BL</UOM></access><access><DelNo>0080000230</DelNo><ItemNo>000020</ItemNo><GText>25# GRAN- GREAT VALUE</GText><Material>G04025G611</Material><Plant>6005</Plant><SLoc>6005</SLoc><RefDoc>mmenon32</RefDoc><RefItem>00000000</RefItem><DelQty>5.000</DelQty><UOM>BG</UOM></access></DelItem></DeliveryData></ns0:DeliveryDBUpdate>

    Hi,
    You need 2 STATEMENT level tags,
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:DeliveryDBUpdate xmlns:ns0="http://test.com/r3_integration">
    <b><DeliveryData1></b>
    <DelHeader action="UPDATE_INSERT">
    <table>DelHeader</table>
    <access>
    <DelNo>0080000230</DelNo>
    <DelType>LF</DelType>
    <XOverwrite>X</XOverwrite>
    <ShipTo>0000000026</ShipTo>
    <SoldTo>0000000026</SoldTo>
    <Priority>00</Priority>
    <DocDate>02/17/2007</DocDate>
    <GText>CIF est</GText>
    <DelDate>02/20/2007</DelDate>
    <PickDate>02/20/2007</PickDate>
    <ShipPoint>NO02</ShipPoint>
    <PackCount>00000</PackCount>
    </access>
    <key>
    <DelNo>0080000230</DelNo>
    </key>
    </DelHeader>
    <b><DeliveryData1></b>
    <b><DeliveryData2></b>
    <DelItem action="INSERT">
    <table>DelItem</table>
    <access>
    <DelNo>0080000230</DelNo>
    <ItemNo>000010</ItemNo>
    <GText>10# GRAN-GREAT VALUE</GText>
    <Material>G04410G611</Material>
    <Plant>6005</Plant>
    <SLoc>6005</SLoc>
    <RefDoc>mmenon32</RefDoc>
    <RefItem>00000000</RefItem>
    <DelQty>5.000</DelQty>
    <UOM>BL</UOM>
    </access>
    <access>
    <DelNo>0080000230</DelNo>
    <ItemNo>000020</ItemNo>
    <GText>25# GRAN- GREAT VALUE</GText>
    <Material>G04025G611</Material>
    <Plant>6005</Plant>
    <SLoc>6005</SLoc>
    <RefDoc>mmenon32</RefDoc>
    <RefItem>00000000</RefItem>
    <DelQty>5.000</DelQty>
    <UOM>BG</UOM>
    </access>
    </DelItem>
    <b></DeliveryData2></b>
    </ns0:DeliveryDBUpdate>
    Try with such a strcuture and let us know if it works.
    Regards
    Bhavesh

  • Update a table using MODIFY

    Hi,
    We need your help.
    We want to update a table using the MODIFY command but it does not delete the previous entries instead it INSERTs a new entry.
    Scenario:
    1. Upon calling the Screen for Editing the entry, the previous entry must be deleted
    2. When SAVEd, the new entry must replace the previous entry.

    Make sure that in the definition or your table you have specified the key. Otherwise, the system may "think" that all the fields are part of the key, therefore all lines are different.
    This is a extract from SAP's documentation:
    "The line to be changed is determined by the fact that the content of the table key matches the content of the corresponding components in the wa work area. For tables with a key that is not unique, the first entry that is found is changed. "
    Regards.

  • Update table using merge or Update statement

    Hi All,
    We have oracle 10G R2 On windows...
    We have tables BROK_DEALER_MAP and DTRMIS_REPORT.
    create table BROK_DEALER_MAP
    SL_NO NUMBER,     
    BROK_DLR_CODE VARCHAR2(30),     
    EMP_TAG     VARCHAR2(30),
    REMARKS     VARCHAR2(60),
    CONS_CODE VARCHAR2(30),     
    BROK_DLR_NAME VARCHAR2(50),
    BROKER_TYPE VARCHAR2(30),
    BROK_DLR_0 VARCHAR2(30),
    CATG_DESC VARCHAR2(60),     
    Category VARCHAR2(30));
    desc DTRMIS_REPORT
    SL_NO
    POSTED_DATE
    ZONE
    AMC_REGION
    CITY
    BROK_DLR_CODE
    BROK_DLR_NAME
    SUB_BROKER
    B_TYPE
    FOLIO_NO
    INVESTOR_NAME
    TAX_NO
    INV_TAG
    SCHEME_CODE
    SCHEME_NAME
    SCH_CLASS
    TRXN_MODE
    CHN_TAG
    FP_COUNT
    FP_AMOUNT
    AP_COUNT
    AP_AMOUNT
    PUR_COUNT
    PUR_AMOUNT
    SIP_COUNT
    SIP_AMOUNT
    SI_COUNT
    SI_AMOUNT
    RED_COUNT
    RED_AMOUNT
    SO_COUNT
    SO_AMOUNT
    DR_COUNT
    DR_AMOUNT
    STP_COUNT
    STP_AMOUNT
    NET_SALES
    DISTRIBUTOR_TYPE
    SCHEME_TYPE
    FOCUS_PRODUCT
    RM_CODE
    RM_NAMEtable BROK_DEALER_MAP doesn't have any duplicate records.
    table DTRMIS_REPORT have more than 2 lacks duplicate records.
    Now i want to update table DTRMIS_REPORT (DISTRIBUTOR_TYPY COLUMN) With the values of BROK_DEALER_MAP (CATEGORY COLUMN).
    For that i have written merge statement like below
    merge into dtrmis_report a
    using brok_dealer_map b
    on (a.brok_dlr_code=b.cons_code)
    when matched then
    update set a.Distributor_type=b.category
    where a.brok_dlr_code=b.cons_code;IT's giving error saying ORA-30926: unable to get a stable set of rows in the source tables.
    How to update the table.
    Please help.

    Chanchal Wankhade wrote:
    IT's giving error saying ORA-30926: unable to get a stable set of rows in the source tables.That means there are duplicate records in your source table.
    Please post the output of the below
    select cons_code
    from brok_dealer_map
    group by cons_code
    having count(*) > 1;In case of duplicate CONS_CODE, you need to decide with which the target table should get updated
    And are you seriously giving a where condition in merge like you posted..?
    Edited by: jeneesh on Dec 19, 2012 9:56 AM

  • Updating a table using subquery

    Hi,
    I need to update a column of test1 table with the values of test2 table
    joining both tables by the code
    update test1 t1 set t1.column1 = (select t2.column2 from test2 t2 where t2.column3 = 'somevalue')
    where t1.code = t2.codethe code that I describe below doesnt works and give me the next error:
    Error SQL: ORA-00904: "t2.code": invalid identifierwhats wrong??
    thanks in advanced

    Hi,
    The outer query (the update) doesn't "see" t2 as it is in the inner query (the select).
    You can either update the join directly :update (
    select t1.column1 col1, t2.column2 col2
    from test1 t1
    left join test2 t2
    on (t1.code=t2.code)
    and t2.column3='somevalue'
    ) v
    set col1=col2;or use merge operation, or add the where clause and use correlated subquery as in :update test1 t1 set t1.column1 = (select t2.column2 from test2 t2 where t2.code = t1.code and t2.column3 = 'somevalue')
    where exists (select null from test2 t2 where t2.code = t1.code and t2.column3 = 'somevalue');

  • Error while updating lookup table through PSI

    Hi,
    I am trying to update a lookuptable through PSI using following code : 
    $lookupTableGuid = $svcPSProxy.ReadLookupTables($EPMTYString, 0 , 1033).LookupTables | where {$_.LT_NAME -eq $Lookuptablename}
    $lookuptable = $svcPSProxy.ReadLookupTablesbyUids($lookupTableGuid.LT_UID, 1 , 1033)
    $lookuptablerowValues = $svcPSProxy.ReadLookupTablesbyUids($lookupTableGuid.LT_UID, 0 , 1033).LookupTableTrees
    #get lookup table count
    $lookuptableValues = $svcPSProxy.ReadLookupTablesbyUids($lookupTableGuid.LT_UID, 0 , 1033).LookupTableTrees
    $count = $lookuptableValues.Count +1
    #Insert the rows of table in Lookup Table
    foreach ($rows in $table)
    $value_Code = $rows.Item("Project_code")
    $value_Name = $rows.Item("project_desc")
    $GUID = [System.Guid]::NewGuid()
    $LookupRow = $lookuptable.LookupTableTrees.NewLookupTableTreesRow()
    $LookupRow.LT_STRUCT_UID = $GUID
    $LookupRow.LT_UID = $lookupTableGuid.LT_UID
    $LookupRow.LT_VALUE_TEXT = $value_Code
    $LookupRow.LT_VALUE_DESC = $value_Name
    $LookupRow.LT_VALUE_SORT_INDEX = ($count ++)
    $lookuptable.LookupTableTrees.AddLookupTableTreesRow($LookupRow)
    $error.clear()
    #Exceptions Handling :
    Try
    $svcPSProxy.UpdateLookupTables($lookuptable , 0 , 1 , 1033)
    Catch
    write-host "Error updating the Lookup table, see the error below:" -ForeGroundColor Red -BackGroundColor White
    write-host "$error" -ForeGroundColor Red
    Initially, I tried to run with value of $value_code as "AACL", the code worked.
    But when I tried to insert value of code as "AACL - ALKYL AMINES CHEMICALS LIMITED"
    I got following error:
    Exception calling "UpdateLookupTables" with "4" argument(s): "Response is not well-formed XML."
    I could not understand why this error is appearing as I just added ' - ' to my code value. I checked for validity of ' -  'in the targeted column. No issue with that.
    Please help.
    Thanks and regards,
    Jayesh

    Hi All,
    The entries are maintained from DB level.
    Thanks for the help.
    DVRK

  • When Importing XML table using "merge content" I get content but none of the formatting

    I'm just wondering, is this by design?
    I generated this by exporting a table.
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Root>
    <Story>
    <Table tblName="tsBasicTable" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid5:tablestyle="tsBasicBody" aid:table="table" aid:trows="7" aid:tcols="9">
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="24.0"/>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="2">Alcohol</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="2">Tobacco</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="2">Marijuana</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="2">Prescription drugs</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="24.0">Grade</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">Town 2013</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">State 2013</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">Town 2013</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">State 2013</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">Town 2013</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">State 2013</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">Town 2013</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">State 2013</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="24.0">6</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">9.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">10.2</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">4.2</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">2.4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">9.6</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">7.2</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">8.4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">11.4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="24.0">8</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">12.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">15.2</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">15.2</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">12.8</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">13.6</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">15.2</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">4.8</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">10.4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="24.0">10</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">9.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">17.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">46.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">44.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">5.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">2.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">38.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">50.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="24.0">12</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">12.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">19.2</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">14.4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">14.4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">16.8</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">32.4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">19.2</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">22.8</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="24.0">All</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">10.5</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">15.4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">20.0</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">18.4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">11.3</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">14.2</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">17.6</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="64.0">23.7</Cell>
    </Table>
    </Story>
    </Root>
    Say I take that XML, change all instances of aid:ccolwidth="24.0" to aid:ccolwidth="26.0" and replace
    <Cell aid:table="cell" aid:crows="1" aid:ccols="2">Alcohol</Cell>
    with
    <Cell aid:table="cell" aid:crows="1" aid:ccols="2">Alcoholism</Cell>
    'I save that XML.
    In ID: Import XML... selecting "Merge Content", "only import elements that match existing structure" & "import text elements into tables if tags match"
    The cell with "Alcohol" updates, but the column widths don't change.
    Is this by design?
    When I select "Append Content" I get a (new) table with the formatting (column widths) as specified in the updated aid:ccolwidth and of course, the updated content. When merging content are you giving up all rights to updating formatting at the same time?
    Thanks in advance for any insights.

    Hello,
    The existence check on the Salutation descriptor is likely check cache, as it is the default. Because of this, when you merge the Salutation with id=2, it will check the cache and not find it and so register it as a new object instead. You have 2 options, the first is to read it instead of creating it new. The second is to change your existence checking option so that it will either go tothe database or assume existence so that it is more appropriate for how you intend to use these types of objects in your mappings. For instance, if you never plan to create new ones, assume existence might be more appropriate.
    I suspect though that for most applications, reading the object first is the best option performance wise.
    Best Regards,
    Chris

  • Migration of million rows from remote table using merge

    I need to migrate (using merge) almost 15 million rows from a remote database table having unique index (DAY, Key) with the following data setup.
    DAY1 -- Key1 -- NKey11
    DAY1 -- Key2 -- NKey12
    DAY2 -- Key1 -- NKey21
    DAY2 -- Key2 -- NKey22
    DAY3 -- Key1 -- NKey31
    DAY3 -- Key2 -- NKey32
    In my database, I have to merge all these 15 million rows into a table having unique index (Key); no DAY in destination table.
    First, it would be executed for DAY1 and the merge command will insert following two rows. For DAY2, it would update two rows with the NKey2 (for each Key) values and so on.
    Key1 -- NKey11
    Key2 -- NKey12
    I am looking for the best possible approach. Please note that I cannot make any change at remote database.
    Right now, I am using the following one which is taking huge time for DAY2 and so on (mainly update).
    MERGE INTO destination D
      USING (SELECT /*+ DRIVING_SITE(A) */ DAY, Key, NKey
                   FROM source@dblink A WHERE DAY = v_day) S
      ON (D.Key = S.Key)
    WHEN MATCHED THEN
       UPDATE SET D.NKey = S.NKey
    WHEN NOT MATCHED THEN
       INSERT (D.Key, D.NKey) VALUES (S.Key, S.NKey)
    LOG ERRORS INTO err$_destination REJECT LIMIT UNLIMITED;Edited by: 986517 on Feb 14, 2013 3:29 PM
    Edited by: 986517 on Feb 14, 2013 3:33 PM

    MERGE INTO destination D
      USING (SELECT /*+ DRIVING_SITE(A) */ DAY, Key, NKey
                   FROM source@dblink A WHERE DAY = v_day) S
      ON (D.Key = S.Key)
    WHEN MATCHED THEN
       UPDATE SET D.NKey = S.NKey
    WHEN NOT MATCHED THEN
       INSERT (D.Key, D.NKey) VALUES (S.Key, S.NKey)
    LOG ERRORS INTO err$_destination REJECT LIMIT UNLIMITED;The first remark I have to emphasize here is that the hint /*+ DRIVING_SITE(A) */ is silently ignored because in case of insert/update/delete/merge the driving site is always the site where the insert/update/delete is done.
    http://jonathanlewis.wordpress.com/2008/12/05/distributed-dml/#more-809
    Right now, I am using the following one which is taking huge time for DAY2 and so on (mainly update).The second remark is that you've realised that your MERGE is taking time but you didn't trace it to see where time is being spent. For that you can either use the 10046 trace event or at a first step get the execution plan followed by your MERGE statement.
    LOG ERRORS INTO err$_destination REJECT LIMIT UNLIMITED;The third remark is related to the DML error logging : be aware that unique keys will empeach the DML error loggig to work correctly.
    http://hourim.wordpress.com/?s=DML+error
    And finally I advise you to look at the following blog article I wrote about enhancing an insert/select over db-link
    http://hourim.wordpress.com/?s=insert+select
    Mohamed Houri
    www.hourim.wordpress.com

  • Updating a Table using Spreadsheet

    Hi,
    There are a couple tables that I would like to update regularly, like once every week. Instead of adding new rows, how can I update the tables by uploading CSV files using the Upload Utilities?
    Thank you very much for your help in advance!

    Here is an easier solution..
    1) Have you DBA create an Oracle directory on the server (it is created in Oracle and maps to a operating system directory.
    2) Create a external table in that directory, have it have the same layout as your spreadsheet
    3) Now when you build the external table, give it the name of the spreadsheet file
    4) You can then copy the file to the directory
    5) Write a small pl/sql script to select from the external table and do a merge of the data selected into the existing table (See merge command syntax here: http://www.oracle.com/technology/products/oracle9i/daily/Aug24.html)
    Thank you,
    Tony Miller
    Webster, TX

  • UPDATE a table using COUNT(*)

    I was wondering if there's a way to write the following code using a single stmt:
    FOR update_rec IN ( SELECT CODE, COUNT(APPOINTMENT) TOT FROM TEST GROUP BY CODE )
    LOOP
    UPDATE TEST
    SET TOT_APPOINTMENT = update_rec.TOT
      WHERE CODE = update_rec.CODE;
    END LOOP;Regards.

    Or use MERGE
    SQL> create table t as
      2  select 'A' code, 1 appointment, 0 tot_appointment from dual union all
      3  select 'A' code, 1 appointment, to_number(null) tot_appointment from dual union all
      4  select 'B' code, 1 appointment, to_number(null) tot_appointment from dual union all
      5  select 'B' code, 1 appointment, to_number(null) tot_appointment from dual union all
      6  select 'B' code, 1 appointment, to_number(null) tot_appointment from dual;
    Table created.
    SQL> select * from t;
    C APPOINTMENT TOT_APPOINTMENT
    A           1               0
    A           1
    B           1
    B           1
    B           1
    5 rows selected.
    SQL> merge into t
      2  using ( select code
      3          ,      count(*) numrecs
      4          from   t
      5          group by code
      6       ) c
      7  on (c.code = t.code)    
      8  when matched then update set t.tot_appointment = c.numrecs;
    5 rows merged.
    SQL> select * from t;
    C APPOINTMENT TOT_APPOINTMENT
    A           1               2
    A           1               2
    B           1               3
    B           1               3
    B           1               3
    5 rows selected.
    SQL>

  • Update a table using OWB

    Hi All,
    I have a unique requirement where the data comes from two different sources using the following cases in perspective
    - Table A and Table B have common ID's but different information regarding the same entity.
    - Table A has the commanding records going into the target table and table B fills in some other details not available in table A.
    so in essence I am merging data which can be accomplished by UPDATE/INSERT ....How ever I am constrained by the date element , data from table B merges in to the target table different for a given period of time , so what I have done is created a bunch of mappings just to update the table with the logic for the different years and I am using the UPDATE operator to update the records and mapping is taking a long time , just to update 122,360 records the mapping has been running for about 2 hours.
    Any suggestions on how to better approach this?
    Regards,
    Malam

    Hi Malam,
    there is no simple answer to your question. Maybe SQL tuning is the most complex subject for relational databases.
    For example of successful SQL tuning look at this thread Hanging deployment
    Regards,
    Oleg

Maybe you are looking for

  • Any update on Mac Pro 2013 ssd upgrade?

    Hi, I was wondering if anyone has any knowledge on weather an SSD upgrade for the current 2013 Mac Pro will be available soon. I bought a new Mac Pro 3.7 GHz Quad-Core Intel Xeon E5 12GB RAM for my music production for my studio, however I'm now find

  • PL/SQL process and popup URL

    Hi, I have a PL/SQL process which is called on submit but a button. This Pl/SQL creates a file on the web-server and I then want to open this file in a new browser window using the URL path to it. Can this be done from pl/sql or do I need to embed so

  • Is it possible to increase I phone 5 storage from 16 GB to 32 GB?

    Can I change I phone 5 storage from 16 GB to 32 GB?

  • DB connectivi​ty toolkit: syntax error in a SELECT data from joined tables

    Hello everyone I'm trying to put in labview an SQL query on joined tables. As example I take a DB for storing the data of 2on2 basketball games, whose tables are matches(matchId,teamA,teamB) teams(teamId,PlayerAname,PlayerBname,Nationality) nationali

  • 4.1EA2 - SQL Worksheet button/dropdown - Main toolbar

    SD: 4.1.0.18.37 Java: 1.8.0_40 I have a large number of connections defined and regularly would like to be able to open a worksheet directly, without opening the connection in the connection tree view. The list that is displayed when the toolbar butt