UPDATE query suggestions

We have a need for an update query, but we're starting with a SELECT statment to make sure that the update will only change the required number of records. We started with:
select t1.act_num, t1.text || ' ' || (select text
                                        from BAC t2
                                       where comtype = 'Request'
                                         and type = 'A'
                                         and t1.act_num = t2.act_num) as appended_text
from BAC t1
where comtype = 'Result'
  and type = 'A'This query takes quite awhile to run, bringing back about 500 records every 30 seconds. The query plan isn't that complex. Full scan on "t1", which makes sense because 1/3 of the type 'A' records have a comtype of 'Result'. Then, there's an index-based retrieval for the "t2" records.
I can write the query another way, which runs in under 20 seconds, but it's format won't fit into an update query:
select t1.act_num, t1.text || ' ' || t2.text as appended_text
from BAC t1, BAC t2
where t1.act_num = t2.act_num
  and t1.comtype = 'Result'
  and t1.type = 'A'
  and t2.comtype = 'Request'
  and t2.type = 'A'I tried already and got a "No key-preserved table" error:
update (select t1.text as t1_text, t2.text as t2_text
          from BAC t1, BAC t2
         where t1.act_num = t2.act_num
           and t1.comtype = 'Result'
           and t1.type = 'A'
           and t2.comtype = 'Request'
           and t2.type = 'A')
   set t1_text = t1_text ||' '||t2_text;So does this mean it's just an update that is destined to be slow? The reason why I'm a bit confused as to the lethargy of the SELECT is that there are only about 350,000 records in this table, about 108,000 of which are actually being updated. It's just not that much data.
Thanks,
--=Chuck

Here's a new one for me ...
That act_num column was the 5th column in a 6-column primary key index. While the logic would have correctly updated the records like we wanted, Oracle would rather have more information. The following ran in a very acceptable time:
select t1.act_num, t1.text || ' ' || (select text
                                        from BAC t2
                                       where comtype = 'Request'
                                         and type = 'A'
                                         and t1.act_num = t2.act_num
                                         and t1.pk1 = t2.pk1
                                         and t1.pk2 = t2.pk2
                                         and t1.pk3 = t2.pk3
                                         and t1.pk4 = t2.pk4
                                      ) as appended_text
from BAC t1
where comtype = 'Result'
  and type = 'A'This is in Oracle 11gR1.
--=Chuck

Similar Messages

  • If statement in update query

    I was wondering if you could have a cfif statement inside of a update query.  See example below.  Is there a better way of doing it? thanks.
    <cfquery DATASOURCE="xxx" name="update">
      UPDATE plant_gen_info
            SET levels_complete = #URL.var0#
                <cfif IsDefined("URLvar13">
                ,Q1_answer = #URL.var13#
                </cfif>
            WHERE ID = #session.member_id#
      </cfquery>

    TheScarecrow,
    Yes, dynamic query statements can be assembled using <cfif>.  I would suggest you switch your IsDefined() to a StructKeyExists() and strongly suggest you make good use of <cfqueryparam>:
    <cfquery DATASOURCE="xxx" name="update">
      UPDATE plant_gen_info
            SET levels_complete = <cfqueryparam value="#URL.var0#" cfsqltype="****">
                <cfif StructKeyExists(URL, "var13")>
                ,Q1_answer = <cfqueryparam value="#URL.var13#" cfsqltype="****">
                </cfif>
            WHERE ID = <cfqueryparam value="#session.member_id#" cfsqltype="****">
      </cfquery>
    I put a "****" placeholder for cfsqltype attributes because I'm not sure which would be appropriate for your variables.  See the help docs for more on the cfqueryparam and cfsqltype.
    -Carl V.

  • If then else in update query

    Hello,
    I was hoping anyone could provide ideas on the best way to do an update query based on an if then else statement I am using Oracle 11 on a linux server. I am writing within a perl script. I've researched online and saw some examples using case. Below is the basic query logic I am trying to implement. I would really appreciate any suggestions.
    Thanks,
    JC
    If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') and askme_temp.CKT_ID = heci.CKT_ID then SUBPRODUCT =’IPAG’
    ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') AND REGION=’SE’ then SUBPRODUCT =’METRO_E’
    ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') then SUBPRODUCT =’OPT_E_MAN’

    Hi,
    Welcome to the forum!
    CASE sounds like a good idea to me.
    For example:
    UPDATE     table_x
    SET     subproduct = CASE
                   WHEN  askme_temp.CKT_ID = heci.CKT_ID
                         THEN  'IPAG'
                   WHEN  region          = 'SE'
                         THEN  'METRO_E'
                         ELSE  'OPT_E_MAN'
                   END
    WHERE     maint_center     IN ( 'ENOC1CENTER'
                      , 'PMCTGAAHSDC'
                      , 'ATTCSPCRT01'
                      , 'ATTCSPCWS01'
                      , 'NTNLWHS4NSA'
    AND   cac1                  = 'S'
    AND   SUBST (ckt_id, 4, 2)  IN ('KQ', 'KR', 'KS', 'KP', 'L1', 'L2', 'L3', 'VL')
    AND   ...
    ;CASE expressions are evaluated in the order in which you write them, so if askme_temp.ckt_id = heci.ckt_id (whatever those things are), subproduct will be set to 'IPAG'. It won't matter whether region is 'METRO_E' or not; if the 1st condition is TRUE, the first THEN value is returned, and the other WHEN expressions aren't even evaluated.
    What do you want to do if none of those conditions are met?
    Any conditions that are common to all the rows being UPDATEd can be put in the WHERE clause; they don't have to be repeated in the CASE expression.
    Remember, MERGE is often more convenient to use than UPDATE.
    Edited by: Frank Kulash on Jul 27, 2011 3:23 PM

  • How Can Improve On Slow Update Query Using /*+ NO_XML_DML_REWRITE */?

    We have an update query recently brought to my attention that is running extremely slow on Oracle 11.2.0.1 against a secure file binary XML table using
    update /*+ NO_XML_DML_REWRITE */croutreach.action set object_value = :1 where actn_id = :2 .
    I am told the majority/near majority of the ~ 16 fields are updated. Also this table has numerous predefined virtual columns with fn based indexes on them.
    My first inclination was to recast this using the Oracle updatexml function. I was told, the /*+ NO_XML_DML_REWRITE */ hint would also be necessary here.
    update /*+ NO_XML_DML_REWRITE */
    <tble_name> a
    set a.object_value = updatexml(a.object_value ...).
    Last year our dba's were instructed by Oracle Support to use this hint, as the update wasn't updating any records w.o any error msgs.
    +1. Hoping to find out if anyone has run across using this hint in some capacity and what was their experience?+
    In trying to optimizie this update statement, I'll start from scratch not using the /*+ NO_XML_DML_REWRITE */ hint and will commence with using the updatexml function with setting up an xmlindex.
    +2. Hoping to receive some suggestions on creating the proper xmlindex - figuring an unstructured index. If get some good performance with the xmlindex; hoping to retire some of the virtual column usage.+
    +3. Any suggestions on living with virtual columns in conjunction with xmlindexes? See the action table definition and associated ivirtual columns and indexes. This table seems over indexed...+
    REATE
      TABLE "CROUTREACH"."ACTION" OF XMLTYPE
        CONSTRAINT "ACTN_ID_PK" PRIMARY KEY ("ACTN_ID") USING INDEX PCTFREE 10
        INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT
        1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1
        FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE
        DEFAULT) TABLESPACE "ACME_DATA" ENABLE
      XMLTYPE STORE AS SECUREFILE BINARY XML
        TABLESPACE "ACME_DATA" ENABLE STORAGE IN ROW CHUNK 8192 CACHE READS LOGGING
        NOCOMPRESS KEEP_DUPLICATES STORAGE(INITIAL 106496 NEXT 1048576 MINEXTENTS 1
        MAXEXTENTS 2147483645 PCTINCREASE 0 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
        CELL_FLASH_CACHE DEFAULT)
      ALLOW NONSCHEMA ALLOW ANYSCHEMA VIRTUAL COLUMNS
        *"ACTION_DEF_URN"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                
    /action/srvContextPointer/outreachActionDefInfo/@actionDefUrn                                              
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(50))),
        *"STAT_DT"* AS (SYS_EXTRACT_UTC(CAST(TO_TIMESTAMP_TZ(SYS_XQ_UPKXML2SQL(
        SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                             
    /action/@status_dt'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2),'SYYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM') AS TIMESTAMP
    WITH
      TIME ZONE))),
        *"ACT_DEF_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                             
    /action/srvContextPointer/outreachActionDefInfo/@actionDefId'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(20))),
        *"CORRL_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                             
    /action/correlationId'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(50))),
        *"STAT_RSN"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                                 
    /action/statusReason'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(30))),
        *"ACT_APPNT_DT"* AS (SYS_EXTRACT_UTC(CAST(TO_TIMESTAMP_TZ(SYS_XQ_UPKXML2SQL(
        SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                 
    /action/actionAppointment/appointment_dt'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2),'SYYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM') AS TIMESTAMP
    WITH
      TIME ZONE))),
        *"UPDT_DT"* AS (SYS_EXTRACT_UTC(CAST(TO_TIMESTAMP_TZ(SYS_XQ_UPKXML2SQL(
        SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                             
    /action/@update_dt'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2),'SYYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM') AS TIMESTAMP
    WITH
      TIME ZONE))),
        *"CRET_DT"* AS (SYS_EXTRACT_UTC(CAST(TO_TIMESTAMP_TZ(SYS_XQ_UPKXML2SQL(
        SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                             
    /action/@create_dt'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2),'SYYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM') AS TIMESTAMP
    WITH
      TIME ZONE))),
        *"ACT_SEQ"* AS (CAST(TO_NUMBER(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                   
    /action/srvContextPointer/outreachActionDefInfo/@sequence'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2)) AS NUMBER(10))),
        *"SERVICE_DEF_URN"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03";                                                         
    /action/srvContextPointer/serviceDefUrn'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(100))),
        *"ASSIGN_TEAM_CD"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                 
    /action/assignment/@teamCategoryCode'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(50))),
        *"ASSIGN_STAFF_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                 
    /action/assignment/staffProfileId'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(50))),
        *"ACTION_TYPE"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03"; (::)                                                     
    declare namespace xsi="http://www.w3.org/2001/XMLSchema-instance"; (::)                                                     
    local-name-from-QName(QName("http://www.cigna.com/acme/domains/actions/2010/03",/action/@xsi:type))                                                                 
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(50))),
        *"ACTN_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03";/action/@id'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(50))),
        *"STATUS"*AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03";/action/@status'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(20))),
        *"ACME_MBR_ID"* AS (CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(XMLQUERY(
        'declare default element namespace "http://www.cigna.com/acme/domains/actions/2010/03";/action/acmeMemberId'
        PASSING BY VALUE SYS_MAKEXML(128,"XMLDATA") RETURNING CONTENT ),0,0,
        16777216,0),50,1,2) AS VARCHAR2(50)))
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
        INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0
        FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
        CELL_FLASH_CACHE DEFAULT
      TABLESPACE "ACME_DATA" ;
    CREATE UNIQUE INDEX *"CROUTREACH"."SYS_C0014547"* ON "CROUTREACH"."ACTION"
        "SYS_NC_OID$"
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
        INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0
        FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
        CELL_FLASH_CACHE DEFAULT
      TABLESPACE "ACME_DATA" ;
    CREATE UNIQUE INDEX *"CROUTREACH"."SYS_IL0000082156C00003$$"* ON "CROUTREACH".
      "ACTION"
        PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576
        MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST
        GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
        TABLESPACE "ACME_DATA" PARALLEL (DEGREE 0 INSTANCES 0) ;
    CREATE UNIQUE INDEX *"CROUTREACH"."ACTN_ID_PK"* ON "CROUTREACH"."ACTION" (
      "ACTN_ID") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(
      INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0
      FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
      CELL_FLASH_CACHE DEFAULT) TABLESPACE "ACME_DATA" ;
      CREATE
        INDEX *"CROUTREACH"."ACTION_STAT_RSN_IDX"* ON "CROUTREACH"."ACTION"
          "STAT_RSN"
        PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
          INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
          0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
          CELL_FLASH_CACHE DEFAULT
        TABLESPACE "ACME_DATA" ;
      CREATE
        INDEX *"CROUTREACH"."ACTION_UPDT_DT_IDX"* ON "CROUTREACH"."ACTION"
          "UPDT_DT"
        PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
          INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
          0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
          CELL_FLASH_CACHE DEFAULT
        TABLESPACE "ACME_DATA" ;
      CREATE
        INDEX *"CROUTREACH"."ACTION_CRET_DT_IDX"* ON "CROUTREACH"."ACTION"
          "CRET_DT"
        PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
          INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
          0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
          CELL_FLASH_CACHE DEFAULT
        TABLESPACE "ACME_DATA" ;
      CREATE
        INDEX *"CROUTREACH"."ACTION_STAT_DT_IDX"* ON "CROUTREACH"."ACTION"
          "STAT_DT"
        PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
          INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
          0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
          CELL_FLASH_CACHE DEFAULT
        TABLESPACE "ACME_DATA" ;
      CREATE
        INDEX *"CROUTREACH"."ACTION_MBRID_TYP_STAT_IDX"* ON "CROUTREACH"."ACTION"
          "ACME_MBR_ID",
          "ACTION_TYPE",
          "STATUS"
        PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
          INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
          0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
          CELL_FLASH_CACHE DEFAULT
        TABLESPACE "ACME_DATA" ;
      CREATE
        INDEX *"CROUTREACH"."ACT_ACTDEF_URN_IDX"* ON "CROUTREACH"."ACTION"
          "ACTION_DEF_URN"
        PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
          INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
          0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
          CELL_FLASH_CACHE DEFAULT
        TABLESPACE "ACME_DATA" ;
      CREATE
        INDEX *"CROUTREACH"."ACTION_ACT_DEF_ID_STATUS_IDX"* ON "CROUTREACH"."ACTION"
          "ACT_DEF_ID",
          "STATUS"
        PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
          INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE
          0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT
          CELL_FLASH_CACHE DEFAULT
        TABLESPACE "ACME_DATA" ;Any suggestions much appreciated.
    Regards,
    Richard Blanchard

    odie 63
    update /*+ NO_XML_DML_REWRITE */croutreach.action set object_value = :1 where actn_id = :2 .
    This update pattern is used in the production environment and is slowing the environment down as more xml content is increased. In a new release build, this update pattern against the action table described earlier, is particularly problematic.
    Have some more information on the /*+ NO_XML_DML_REWRITE */ hint. It turns out, last year, updates statements would intermittently fail to correctly update silently failing. An Oracle Service Request was created. Over the span of about 5 mnths, Oracle determined a very low level Oracle kernel bug was the culprit. Oracle As a result of this SR, Oracle SUpport created BUG 11939507 <ORA-08102: index key not found during update on xmltable with a virtual column>. This bug is viewable on metalink. Oracle claims this bug has only been oberved on In the interim to 11.2.0.3, Oracle Support mentioned to use /*+ NO_XML_DML_REWRITE */; thus disabling piecewise update.
    Here's preface information on this bug:
    Bug 11939507: ORA-08102: INDEX KEY NOT FOUND DURING UPDATE ON XMLTABLE WITH VIRTUAL COLUMN  
    Bug Attributes
    Type B - Defect Fixed in Product Version 12.1
    Severity 2 - Severe Loss of Service Product Version 11.2.0.1
    Status 80 - Development to Q/A Platform 23 - Oracle Solaris on SPARC (64-bit)
    Created 30-Mar-2011 Platform Version 10
    Updated 13-Feb-2012 Base Bug -
    Database Version 11.2.0.1  
    Affects Platforms Generic  
    Product Source Oracle  
    Hdr: 11939507 11.2.0.1 XDB 11.2.0.1 BINARY PRODID-5 PORTID-23
    Abstract: ORA-8102: INDEX KEY NOT FOUND DURING UPDATE ON XMLTABLE WITH VIRTUAL COLUMN*** 03/30/11 12:22 pm ***
    BUG TYPE CHOSEN  =============== code   
    Component: XML Database  ======================= 
    DETAILED PROBLEM DESCRIPTION  ============================ 
    The issue happens intermittently when running a batch program with 50  concurrent sessions that involves high concurrent updates.
    DIAGNOSTIC ANALYSIS  ===================  reproducible testcase on customer dummy data reproduced by Thomas. 
    WORKAROUND?  ===========  No   
    TECHNICAL IMPACT  ================  Customer is experiencing this error which is critical to the application  because it causes a home health care provider to possibly lose a couple  hours worth of work and have to start from scratch. The condition has only  accessed concurrently from about 40 threads  
    RELATED ISSUES (bugs, forums, RFAs)  ===================================  Bug 8514561 - ORA-8102 WHEN UPDATING TABLE
    HOW OFTEN DOES THE ISSUE REPRODUCE AT CUSTOMER SITE?  ====================================================  Intermittent  
    DOES THE ISSUE REPRODUCE INTERNALLY?  ====================================  Intermittent
    IS A TESTCASE AVAILABLE?  ========================  Yes  The good news is, this bug is corrupting a virtual index column.
    I'll try test cases using the update pattern; 'update /*+ NO_XML_DML_REWRITE */croutreach.action set object_value = :1 where actn_id = :2 ' - substituting actual values for the bind variables and removing interfering virtual columns. Wil lcompare with and w/o the hint.
    This wil address your; "Where does the new values come from? Individual variables?" - and provide sample data.
    Presently, this update pattern is used 'blindly' in that when no xml relevent changes are identified, only a couple of the roughly 16 fields are updated - yet the whole document gets updated with this update pattern. When changes occur, the whole document is updated. Will work with updating 1 or 2 fields using updatexml and try the xmlexists function for the predicate.
    04/25/12 Update:
    odie 63,
    Here's a sample xml record from the action securefile binary xml table:
    <?xml version = '1.0' encoding = 'UTF-8' standalone = 'yes'?><action xsi:type="AssessmentActionType" status_dt="2012-01-18T19:38:21.077Z" status="not applicable" create_dt="2012-01-17T23:10:16.173Z" id="dfdfdfdfdfddfdfdfdfdfdf" xmlns:ns5="http://www.xxxxx.ddd/exception/definition/schema/2010/01" xmlns="http://www.xxxxxx.ddd/mmm/domains/actions/2010/03" xmlns:ns6="http://www.xxxxx.ddd/mmm/domains/utility/outcome/2010/03" xmlns:ns7="http://www.xxxxxx.ddd/mmm/domains/common/2010/03" xmlns:ns2="http://www.xxxxx.ddd/mmm/messages/actions/2010/03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://www.xxxxx.ddd/mmm/domains/workforce/2010/03" xmlns:ns4="http://www.xxxxxx.ddd/mmm/domains/entitlement/2011/11">
       <acmeMemberId>abcdefghijklmnop</acmeMemberId>
       <advocacyPlanId>qrstuvwxyz</advocacyPlanId>
       <srvContextPointer>
          <serviceDefUrn>urn:coderunner:Medical:Definition:ServiceService:11111:7</serviceDefUrn>
          <outreachActionDefInfo sequence="1" actionDefUrn="urn:xxxxxxxxxx:Medical:Definition:Action:50813:2" actionDefId="xxxxxx">
             <srvContextPath>Access Profile~Why did you access the profile?~Reason for access?</srvContextPath>
          </outreachActionDefInfo>
       </srvContextPointer>
    </action>Started out using this update statement against the virtual column a.actn_id. This column is also indexed as a fbi.
    UPDATE /*+ NO_XML_DML_REWRITE */ action A
    SET A.object_value = updatexml(A.object_value,'/action/@status','triggered','xmlns="http://www.xxxx.vvv/yyy/domains/actions/2010/03"')
    where a.actn_id='888a80be-d69f-464d-b3f7-85b6209f918e';
    This statment updates fine with and w/o the hint. This hint takes away the piecewise update of the xml document and relies upon the a.actn_id virtual column.
    Then removed the reliance on the virtual column using the xmlexists fn.
    First did an alter index 'actn_id_pk invisible' to take the virtual column out of consideration by the optimizer.
    UPDATE /*+ NO_XML_DML_REWRITE */ action A
    SET A.object_value = updatexml(A.object_value,'/action/@status','triggered','xmlns="http://www.xxxx.vvv/yyy/domains/actions/2010/03"')
    where xmlexists('$p/action[@id="'888a80be-d69f-464d-b3f7-85b6209f918e'"]' PASSING object_value as "p");
    This update runs but doesn't update any columns - with or without the hint.
    Also created a basic unstructured xmlindex to remove the full table scan - which worked fine execution plan-wise.
    create index action_xmlindex_ix on action (object_value) indextype is xdb.xmlindex;Per the SR on this, the /*+ NO_XML_DML_REWRITE */ disables piecewise update and is a workaround for the bug surrounding virtual column index usage when having many concurrent sessions and updates against a table with millions of xml documents. Getting rid of the virtual column in the predicate removes the need for the workaround hint.
    My problem is This update runs but doesn't update any columns. Maybe am missing something or doing a syntax/semantic error ?
    Any assistance much appreciated...
    Regards,
    Rick Blanchard
    Edited by: RickBlanchardSRSCigna on Apr 25, 2012 12:52 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to generate a dynamic update query to update error flag in a mapping?

    i have a mapping in which i m loading log table through generated parameter file.But i want to update the error flag using dynamic update query.for that i have to generate a query and use update sqloverridw in target instances.but i m not getting how to implement it.Please help..!!

    Hi  All, I have a scenario. Below is the source record. field1|field2|field3|field4|field5|field6|field7
    5|20150329|1|980100001|500|My name is Lalita|25
    5|20150329|1|303444442|200|My name is |Lalita.I work in TCS|26
    5|20150329|1|442101001|1000|My name is Lalita.I worked Syntel|56
    5|20150329|1|446788900|300|My name|67  My source file is | separator. But for field6 the data might come with '|'.
    So I want to import the data along with '|' after separating all field in Informatica Layer.  Source team is not going to preformat the file. Please suggest how to achive this.

  • Update Query is Performing Full table Scan of 1 Millions Records

    Hello Everyboby I have one update query ,
    UPDATE tablea SET
              task_status = 12
              WHERE tablea.link_id >0
              AND tablea.task_status <> 0
              AND tablea.event_class='eventexception'
              AND Exists(SELECT 1 from tablea ltask where ltask.task_id=tablea.link_id
              AND ltask.task_status = 0)
    When I do explain plan it shows following result...
    Execution Plan
    0 UPDATE STATEMENT Optimizer=CHOOSE
    1 0 UPDATE OF 'tablea'
    2 1 FILTER
    3 2 TABLE ACCESS (FULL) OF 'tablea'
    4 2 TABLE ACCESS (BY INDEX ROWID) OF 'tablea'
    5 4 INDEX (UNIQUE SCAN) OF 'PK_tablea' (UNIQUE)
    NOW tablea may have more than 10 MILLION Records....This would take hell of time even if it has to
    update 2 records....please suggest me some optimal solutions.....
    Regards
    Mahesh

    I see your point but my question or logic say i have index on all columns used in where clauses so i find no reason for oracle to do full table scan,,,,
    UPDATE tablea SET
    task_status = 12
    WHERE tablea.link_id >0
    AND tablea.task_status <> 0
    AND tablea.event_class='eventexception'
    AND Exists(SELECT 1 from tablea ltask where ltask.task_id=tablea.link_id
    AND ltask.task_status = 0)
    I am clearly statis where task_status <> 0 and event_class= something and tablea.link_id >0
    so ideal case FOR optimizer should be
    Step 1)Select all the rowid having this condition...
    Step 2)
    For each row in rowid get all the row where task_status=0
    and where taskid=linkid of rowid selected above...
    Step 3)While looping for each rowid if it find any condition try for rowid obtained from ltask in task 2 update that record....
    I want to have this kind of plan,,,,,does anyone know how to make oracle obtained this kind of plan......
    It is try FULL TABLE SCAN is harmfull alteast not better than index scan.....

  • Bulk Update query

    Hello Friends,
    Can some one suggest me is that any possible bulk update query which consumes less timings?
    Table - MyTable
    id - PK.
    orderid - Order Id.
    Subid - Sub Id for an Order.
    lineitem - LineItemId.
    ProducId - Product Id.
    Now i want to update the Subid to My Table for Every Order on Basis of LineItemId..
    For Ex:
    I will be having the records in MyTable as for a single Order...there can mutilple Subid's.
    UPDATE MyTable SET subid = 1 WHERE orderid = 123 AND lineitem = 1;
    UPDATE MyTable SET subid = 1 WHERE orderid = 123 AND lineitem = 2;
    UPDATE MyTable SET subid = 5 WHERE orderid = 123 AND lineitem = 2000;
    I worked out three scenarios as follows,
    Case1:
    UPDATE MyTable SET subid = 5 WHERE orderid = 123 AND lineitem = 2000;
    Case2:
    UPDATE MyTable SET subid = 1 WHERE orderid = 123 AND lineitem in(1,2,3.....1000);
    UPDATE MyTable SET subid = 2 WHERE orderid = 123 AND lineitem in(1001,1002,.....1100);
    Case3:
    UPDATE MyTable SET subid= CASE WHEN lineitem = 1 THEN 1 WHEN lineitem = 2 THEN 2 .....WHEN 1000 THEN 1000 END WHERE orderid = 123;
    Please suggest me which update consumes less time and helpful for updating more records nearly 5000 - 10000 at a single table.

    You are comparing three cases that are not equal to each other:
    Case1:
    UPDATE MyTable SET subid = 5 WHERE orderid = 123 AND lineitem = 2000;
    Here you update the records with orderid = 123 and lineitem = 2000
    Case2:
    UPDATE MyTable SET subid = 1 WHERE orderid = 123 AND lineitem in(1,2,3.....1000);
    UPDATE MyTable SET subid = 2 WHERE orderid = 123 AND lineitem in(1001,1002,.....1100);
    This are multiple update statement to update all records with orderid = 123 and lineitems between 1 and 1100.
    Case3:
    UPDATE MyTable SET subid= CASE WHEN lineitem = 1 THEN 1 WHEN lineitem = 2 THEN 2 .....WHEN 1000 THEN 1000 END WHERE orderid = 123;
    And here all records with orderid = 123, regardless of the lineitem are updated.
    So my guess is that 1 will be the fastest as it is updating the least amount of records, followed by 2 and then 3. But it is a really weird comparison.
    I think you'd better make up your mind first about which records need to be updated and how. And then it is best to use one update statement to do the job.
    Regards,
    Rob.

  • Update query in HQL.

    Hi,
    Can you suggest me the format of the update query for HQL
    Thanks in advance.

    Read the documentation, google for tutorials and examples.

  • Improve Query Suggestions Load time

    How can I improve load time for Pre Query Suggestions on search home page when user start typing ?? 
    I notice it was slow in loading when I hit first time in the morning so I try to warm up by adding
    ""http://SiteName/_api/search/suggest?querytext='sharepoint' ""
    in to warm up script but even during the day time after hitting few times it is slower some times . Any reason ? 
    Do you think moving Query Component to WFE will do any help here?
    Pleas let me know - Thanks .  

    Hi,
    Query Suggestions should work at a high level overview is:
    • You issue a query within a Search Center site and get results..
    • When you hover over or click a result.. this gets stored as a “RecordPageClick” method and will be stored in the Web Applications W3WP process…
    • Every five minutes ( I believe ) this W3WP will flush these Recorded Page Clicks and pass them over to the Search Proxy…
    • This will then store them in a table in the SSA ( Search Service Application ) Admin DB
    • By default, once a day, there is a timer job, Prepare Query Suggestions, that will run
    • It does a check to see if the same term has been queried for and clicked at least 6 times and then will move them to another table in the same DB..
    • If there are successful queries\clicks > 6 times for a term, and they move to the appropriate table, then when you start to type a word, like “share”
    • This will fire a “method” over to the Search proxy servers called “GetQuerySuggestions” and will check that Admin DB to see if they have any matches..
    • If so, then it will show up in your Search Box as like “SharePoint” for a suggestion…
    Other components involved with the Query Suggestions:
    Timer Jobs
    Prepare query suggestions                   Daily
    Query Classification Dictionary Update for Search Application Search Service Application       Minutes
    Query Logging                    Minutes
    Database
     MSSQLogQuerySuggestion (SearchDB)  This gets cleaned up when we run the timer job
     MSSQLogQueryString (SearchDB)  Info on the Query String
     MSSQLogSearchCounts (SearchDB)  Info on the click counts
     MSSQLogQuerySuggestion Looks like this may be where the hits for suggestions are stored
    So the issue might related to timer job, database, connection between SharePoint server and SQL server. There is  a similar case caused by DistributedCache.
    If you move query component on to another sever, this may improve the process related to Search service, however, it may affect the performance due to networking.
    Please collect verbose ULS log per steps below:
    Enable Verbose logging via Central Admin> Monitoring> Reporting>Configure diagnostic logging(You can simply set all the categories with Verbose level and I can filter myself).
    Reproduce the issue(Try to remove SSRS).
    Record the time and get a capture of the error message(including the correlation ID if there is). Collect the log file which is by default located in the folder:  <C:\Program files\common files\Microsoft Shared\web server extensions\15\LOGS>.
    Stop verbose logging.
    Regards,
    Rebecca Tu
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected].

  • Optimization of Update Query???

    Hello guys!
    I just finished writing an update query, which works but takes forever (approximately 20-30 seconds). Do you have any ideas how it can be optimized in order to run faster? Would it be reccomendable to create a new view that includes only the required columns for the Inner-Select Statement? Right now there are about 20 columns in VT_TBL_PUNKTDATEN_JOIN. Could the statement be written differently to speed up the execution???
    Here is the statement:
    begin
    UPDATE TBL_PUNKTDATEN v SET v.INT_ZAEHLFAKTOR_BESTAND = :P700_INT_ZAEHLFAKTOR_BESTAND
    WHERE EXISTS (SELECT p.INV_PT_ID_SUB FROM VT_PUNKTDATEN_JOIN p WHERE
    (p.STR_GEBIET_MAIN = :P700_STR_GEBIET) and (p.STR_LRT_MAIN = :P700_STR_LRT) and (v.INV_PT_ID_SUB = p.INV_PT_ID_SUB));
    end;I'm really curious if you have any solution for this!
    I Appreciate your effort!
    Bye,
    Sebastian

    skahlert wrote:
    @ Sven W.
    I receive an ORA-01779 error (cannot modify a column which maps to a non key-preserved table).I thought that this would happen (based on your table names), but it was worth a try.
    The problem is which table is the parent and which one is the child table. When joining two tables via a foreign key relationship the child table will be the so-called key-preserved table. This means one row from the source table can be matched to exactly one row in the joined output (=view).
    In your case you can't use the update construct I suggested. It would work if you want to update the other table p.
    However you could measure how long the join select is running and compare that to the update part. This can give a first indication if the select is slow or the update.
    A further try can be to change the correlated subquery into an uncorrelated subquery. I doubt that this will help since the oracle optimzier can do this transformation by itself. Other than that you need to give us more information about table sizes and execution plans. You can always trace the update and see where the time is spent.
    uncorrelated
    UPDATE TBL_PUNKTDATEN v
    SET v.INT_ZAEHLFAKTOR_BESTAND = :P700_INT_ZAEHLFAKTOR_BESTAND
    WHERE v.INV_PT_ID_SUB IN (SELECT p.INV_PT_ID_SUB FROM VT_PUNKTDATEN_JOIN p
                   WHERE p.STR_GEBIET_MAIN = :P700_STR_GEBIET
                   and p.STR_LRT_MAIN = :P700_STR_LRT);Edited by: Sven W. on Aug 19, 2009 1:17 PM

  • Run update query on page load

    Hello All
    This is my first post here, am hoping some of the more experienced guys/girls can help me. I just started using apex a few weeks ago for a College project.
    I am having a problem that has had me stuck for hours now.
    I have an interactive report on a page. What i want to do is run an update query that will pass values into another collum for each row everytime the page is opened.
    This is the query:
    UPDATE confectionary d
    SET itemprice_test = (SELECT price_per_item
    FROM confectionary c
    WHERE d.confect_id = c.confect_id )
    I have tried, what feels like every option for this as well as many google searches.
    Does anyone have a suggestion that could solve this problem?
    Thanks

    not sure if i completely understand you..
    just my 2 cents..
    if you want to run the same update command that you posted..
    go to you page..
    create a ""onload before header process" --> PL/SQL with the following code.
    {code}
    begin
    UPDATE confectionary d
    SET itemprice_test = (SELECT price_per_item
    FROM confectionary c
    WHERE d.confect_id = c.confect_id )
    end;
    {code}
    For creating ""onload before header process"
    1)edit the page
    2) create process
    3)select PL/SQL
    4)select ""point as"" : On load before header
    sorry..if i a am wrong..

  • SQLSERVER to ORACLE conversion - Update query

    Hi,
    I have a query in sqlserver :
    UPDATE
    netVIEWplus.dbo.DIM_OUC_Latest
    SET
    OUC = LatestFixed.OUC,
    OUC_Desc = LatestFixed.OUC_Desc,
    OUC_Level = LatestFixed.OUC_Level,
    Parent_OUC = LatestFixed.Parent_OUC,
    CC_Type = LatestFixed.CC_Type,
    GFR = LatestFixed.GFR,
    CORP = LatestFixed.CORP,
    SOB = LatestFixed.SOB,
    Div_Unit = LatestFixed.Div_Unit,
    Div_Desc = LatestFixed.Div_Desc,
    L1_OUC = LatestFixed.L1_OUC, L1_DEPT_DESC = LatestFixed.L1_DEPT_DESC,
    L2_OUC = LatestFixed.L2_OUC, L2_DEPT_DESC = LatestFixed.L2_DEPT_DESC,
    L3_OUC = LatestFixed.L3_OUC, L3_DEPT_DESC = LatestFixed.L3_DEPT_DESC,
    L4_OUC = LatestFixed.L4_OUC, L4_DEPT_DESC = LatestFixed.L4_DEPT_DESC,
    L5_OUC = LatestFixed.L5_OUC, L5_DEPT_DESC = LatestFixed.L5_DEPT_DESC,
    L6_OUC = LatestFixed.L6_OUC, L6_DEPT_DESC = LatestFixed.L6_DEPT_DESC,
    L7_OUC = LatestFixed.L7_OUC, L7_DEPT_DESC = LatestFixed.L7_DEPT_DESC,
    L8_OUC = LatestFixed.L8_OUC, L8_DEPT_DESC = LatestFixed.L8_DEPT_DESC,
    Current_Flag = LatestFixed.Current_Flag,
    INF_Div_Unit_Only = LatestFixed.INF_Div_Unit_Only,
    INF_DIM_OUC_Id_Used = LatestFixed.DIM_OUC_Id
    FROM
    netVIEWplus.dbo.DIM_OUC_Latest
    INNER JOIN
    netVIEWplus.dbo.DIM_OUC HistoryDIM
    ON
    HistoryDIM.DIM_OUC_Id = netVIEWplus.dbo.DIM_OUC_Latest.DIM_OUC_Id
    INNER JOIN
    netVIEWplus.dbo.DIM_OUC LatestDIM
    ON
    LatestDIM.DIM_OUC_ID = HistoryDIM.Latest_Id
    INNER JOIN
    netVIEWplus.dbo.DIM_OUC LatestFixed
    ON
    netVIEWplus.dbo.DIM_OUC_Latest.OUC = LatestFixed.OUC
    WHERE
    LatestDIM.INF_Updateable = 1
    AND
    LatestFixed.Valid_From =
    SELECT MAX(Valid_From)
    FROM netVIEWplus.dbo.DIM_OUC
    WHERE OUC = LatestFixed.OUC
    AND INF_Updateable = 0
    Which I want to convert in oracle like below :
    UPDATE
    netVIEWplus.DIM_OUC_Latest T1
    SET (OUC,OUC_Desc,OUC_Level,Parent_OUC,CC_Type,GFR,CORP,SOB,Div_Unit,Div_Desc,L1_OUC,L1_DEPT_DESC,L2_OUC,
    L2_DEPT_DESC,L3_OUC,L3_DEPT_DESC,L4_OUC,L4_DEPT_DESC,L5_OUC,L5_DEPT_DESC,L6_OUC,L6_DEPT_DESC,L7_OUC,L7_DEPT_DESC,
    L8_OUC,L8_DEPT_DESC,Current_Flag,INF_Div_Unit_Only,INF_DIM_OUC_Id_Used) =
    (SELECT LatestFixed.OUC OUC,LatestFixed.OUC_Desc OUC_Desc,
    LatestFixed.OUC_Level OUC_Level,LatestFixed.Parent_OUC Parent_OUC,LatestFixed.CC_Type CC_Type,LatestFixed.GFR GFR,
    LatestFixed.CORP CORP,LatestFixed.SOB SOB,LatestFixed.Div_Unit Div_Unit,LatestFixed.Div_Desc Div_Desc,
    LatestFixed.L1_OUC L1_OUC,LatestFixed.L1_DEPT_DESC L1_DEPT_DESC,LatestFixed.L2_OUC L2_OUC,LatestFixed.L2_DEPT_DESC L2_DEPT_DESC,
    LatestFixed.L3_OUC L3_OUC,LatestFixed.L3_DEPT_DESC L3_DEPT_DESC,LatestFixed.L4_OUC L4_OUC,
    LatestFixed.L4_DEPT_DESC L4_DEPT_DESC,LatestFixed.L5_OUC L5_OUC,LatestFixed.L5_DEPT_DESC L5_DEPT_DESC,
    LatestFixed.L6_OUC L6_OUC,LatestFixed.L6_DEPT_DESC L6_DEPT_DESC,LatestFixed.L7_OUC L7_OUC,
    LatestFixed.L7_DEPT_DESC L7_DEPT_DESC,LatestFixed.L8_OUC L8_OUC,LatestFixed.L8_DEPT_DESC L8_DEPT_DESC,
    LatestFixed.Current_Flag Current_Flag,LatestFixed.INF_Div_Unit_Only INF_Div_Unit_Only,
    LatestFixed.DIM_OUC_Id INF_DIM_OUC_Id_Used
    FROM
    netVIEWplus.DIM_OUC HistoryDIM,netVIEWplus.DIM_OUC LatestDIM,netVIEWplus.DIM_OUC LatestFixed
    where
    HistoryDIM.DIM_OUC_Id = T1.DIM_OUC_Id
    AND
    LatestDIM.DIM_OUC_ID = HistoryDIM.Latest_Id
    and
    T1.OUC = LatestFixed.OUC
    and
    LatestFixed.INF_Updateable = 1
    AND
    LatestFixed.Valid_From =
    SELECT MAX(Valid_From)
    FROM netVIEWplus.DIM_OUC
    WHERE OUC = LatestFixed.OUC
    AND INF_Updateable = 0
    and rownum=1)
    where exists
    (SELECT 1
    FROM
    netVIEWplus.DIM_OUC HistoryDIM,netVIEWplus.DIM_OUC LatestDIM,netVIEWplus.DIM_OUC LatestFixed
    where
    HistoryDIM.DIM_OUC_Id = T1.DIM_OUC_Id
    AND
    LatestDIM.DIM_OUC_ID = HistoryDIM.Latest_Id
    and
    T1.OUC = LatestFixed.OUC
    and
    LatestFixed.INF_Updateable = 1
    AND
    LatestFixed.Valid_From =
    SELECT MAX(Valid_From)
    FROM netVIEWplus.DIM_OUC
    WHERE OUC = LatestFixed.OUC
    AND INF_Updateable = 0
    Problem is, it is taking long time to execute in oracle. Find the explain plan of the oracle query :
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    UPDATE STATEMENT Optimizer Mode=ALL_ROWS          1           19 M                    
    UPDATE     NETVIEWPLUS.DIM_OUC_LATEST                                   
    HASH JOIN SEMI          1      216      19 M                    
    TABLE ACCESS FULL     NETVIEWPLUS.DIM_OUC_LATEST     299 K     55 M     1550                     
    VIEW     SYS.VW_SQ_3     4 G     90G     12 M                    
    HASH JOIN          4 G     208G     12 M                    
    TABLE ACCESS FULL     NETVIEWPLUS.DIM_OUC     298 K     2 M     2009                     
    MERGE JOIN CARTESIAN          4 G     167G     1664177                     
    HASH JOIN          14 K     516 K     4873                     
    TABLE ACCESS FULL     NETVIEWPLUS.DIM_OUC     53 K     945 K     2030                     
    VIEW     SYS.VW_SQ_2     81 K     1 M     2841                     
    SORT GROUP BY          81 K     1 M     2841                     
    TABLE ACCESS FULL     NETVIEWPLUS.DIM_OUC     245 K     4 M     2030                     
    BUFFER SORT          298 K     1 M     1664177                     
    INDEX FAST FULL SCAN     NETVIEWPLUS.DIM_OUC_PK     298 K     1 M     113                     
    COUNT STOPKEY                                        
    NESTED LOOPS          1      253      4062                     
    NESTED LOOPS          1      235      2032                     
    NESTED LOOPS          1      15      2                     
    TABLE ACCESS BY INDEX ROWID     NETVIEWPLUS.DIM_OUC     1      10      2                     
    INDEX UNIQUE SCAN     NETVIEWPLUS.DIM_OUC_PK     1           1                     
    INDEX UNIQUE SCAN     NETVIEWPLUS.DIM_OUC_PK     298 K     1 M     0                     
    TABLE ACCESS FULL     NETVIEWPLUS.DIM_OUC     1      220      2030                     
    VIEW     SYS.VW_SQ_1     1      18      2030                     
    SORT GROUP BY          3      54      2030                     
    TABLE ACCESS FULL     NETVIEWPLUS.DIM_OUC     3      54      2030                     
    Can any one suggest how to efficiently write the update query.
    Regards,
    Koushik

    Hi,
    Have you gathered stats as well ? Did the query use index(es) as well ?
    Without any more info like explain plan, indexes, etc., further help will be unable.
    Nicolas.

  • Insert and update query to calculate the opening and closing balance

    create table purchase(productid number(5) ,dateofpurchase date,
    qty number(5));
    create table inventory(invid number(5),productid number(5),
    idate date,openingqty number(5),closingqty number(5));
    Records in inventory:
    1,1,'01-jan-2009', 10, 20
    2,1,'03-jan-2009', 20, 30
    3,1,'04-jan-2009', 40, 50
    when I enter the purchase invoice for 15 qty on 02-jan-2009
    after say '15-jan-09' , a new record should get inserted
    with opening balance = (closing balance before 02-jan-2009)
    and all the opening and closing balance for that product should
    get affected.
    If the invoice for 20 qty is entered for the existing date say
    '03-jan-2009' in inventory , then the closing balance
    for 03-jan-2009 should get updated and all the following records
    should get affected.
    I need the insert for the first one and update query for the
    second one.
    Vinodh

    <strike>You can do this in one statement by using the merge statement</strike>
    Hmm, maybe I spoke too soon.
    Edited by: Boneist on 25-Sep-2009 13:56
    Thinking about it, why do you want to design your system like this?
    Why not simply have your purchases table hold the required information and then either work out the inventory on the fly, or have a job that calls a procedure to add a row for the previous day?
    If you continue with this design, you're opening yourself up to a world of pain - what happens when the data doesn't match the purchases table? Also when is the inventory cut-off to reset the opening/closing balances? Monthly? Annually? Weekly? If it's set to one of those, what happens when the business request the inventory for a particular week?
    Edited by: Boneist on 25-Sep-2009 13:59

  • About update query

    Hello :),
    I am a MS SQL Server expert [;)]. trying to learn ORACLE.
    I tried to assign some value to a variable in an update query. I got error message that virtual columns are not allowed. This is very important to get rolling effect.
    Can some one please guide me about how to get rolling effect if we can not assign a value to a variable in an update query.
    Thanx in advance.
    Nishu

    hello sgalaxy and gintsp, thanx for ur reply.
    My reply is so late because for some reason I was not able to log on to this site.
    There is some good reason why I need this. I am giving code and error messages below, please guide me.
    ==============================
    I am trying this thing in procedure. I am using ORACLE DATABASE EXPRESS EDITION
    Here is the code.
    create or replace procedure "PROC1"
    is
    TYPE Bal_Collect IS TABLE OF NUMBER;
    Collt Bal_Collect := Bal_Collect(100);
    begin
    Update empAccount Set Bal = Collt(Collt.Last) Returning Bal BULK COLLECT INTO Collt;
    end;
    Error message
    Compilation failed,line 6 (02:20:45)
    PLS-00425: in SQL, function argument and return types must be SQL type
    Compilation failed,line 6 (02:20:45)
    PL/SQL: ORA-00904: : invalid identifier
    Compilation failed,line 6 (02:20:45)
    PL/SQL: SQL Statement ignored
    BUT FOLLOWING UPDATE STATEMENT WORKS
    Update empAccount Set Bal = Collt(1) Returning Bal BULK COLLECT INTO Collt;

  • When Firefox last automatically updated, it suggested that Adobe reader needed updating, now, with Adobe Reader 8, I can no longer print from the internet, only to file. Help please.

    When Mozilla Firefox last automatically updated, it suggested that Adobe Reader needed updating. After updating to Adobe Reader 8, I can no longer print from the internet, only to a file. I know the printer and its interface must be OK because Word prints normally.

    Problem solved, it was my oversight, I had not removed the check from the Print to File box in the print set up.

Maybe you are looking for

  • Alv Grid Sub Total

    Hi All        I am have done an object in alv grid where it is working fine but what i want i am giving a sample please do let tell me how to do OUTPUT DATE       TIME-ENTRY  ACM-NO   CHARG    SHIFT   MACHINE-SPEED STANDARD-D    ACTUALL-DIPS   DOWNTI

  • File 2 soap problem

    hi i am configuring file to soap scenario. on reciever side (soap) shuold i create communication channel in business service or business system plz help me thanks & regards viju

  • I closed my search bar on accident and cant reopen it how do i get it to pop back up?

    my tool bar to search is gone how do i get it to come back i hint something that closed it on accident

  • "This entry is already exists in tables(JDT1)(ODBC-2035)" Error.

    Hi experts, My Production_DB Database was got into  Suspect mode due to power problem,the users unable to open SAP. so  run the script file so production_db came into normal mode and sap opened. But which documents were posted at the time of database

  • RMB/CNY exchange rate Chinese company code

    Dear all, When posting an invoice for a PO made in RMB(chinese renminbi) SAP errors that no exchange rate is maintained for this currency. This is correct because we only maintain CNY currency because it's the same and it's set as company code curren