Update query using FORALL statement

Hi ALL,
I have two tables Table: Mater_A(20 Cloumns) and Temp_A(20 Columns).
Both are almost identical. The Master_A is master table that has to be updated daily based on the temporary table Temp_A.
Everyday , i expect around 100000 records(same records with modified valus ) in Temp_A that has to be updated in Master_A. So i have to make the query as optimized as possible.
For this,I have created a cursor that has all records from table Temp_A.
Then i am using FORALL statement to update the data. But it throws exception something like that:
Error: PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
Error: PLS-00382: expression is of wrong type
It states that i have to create a separate type for each column that i want to update.
I have created procedure like this:
Open C_Temp_A;
Loop
Fetch C_Temp_A Bulk Collect into v_C_Temp_A limit 5000;
Exit When C_Temp_A%NOTFOUND;
Begin
ForAll i in v_C_Temp_A.first.. v_C_Temp_A.Last
Update Master_A mst Set mst.Column2= v_C_Temp_A(i).t_Column2,
mst.Column3= v_C_Temp_A(i).t_Column3,mst.Column4= v_C_Temp_A(i).t_Column4........to all columns
where mst.Column1= v_C_Temp_A(i).t_Column1;
End;
End Loop;
Close C_Temp_A;
Please help me to solve this or suggest me any other alternative to reduce the processing time.

Why cant you use like :(Or I misread?)
SQL> select * from a;
        ID         C2
         1        100
SQL> select * from b;
        ID         C2
         1       1000
SQL> merge into b
  2  using(select * from a) a
  3  on (b.id = a.id)
  4  when matched then
  5   update
  6   set b.c2 = a.c2;
1 row merged.
SQL> select * from b;
        ID         C2
         1        100                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Creating Query using Financial Statement version (Hierarchy)

    Hi All,
    I've created a Query using Finacial Statement version (0GLACCEXT) against the 0FIGL_VC2 Remote cube.I'm not familiar with Hierarchies. Now I want to run the query based on the 0GLACCEXT .It has revenue nodes .Under the revenue nodes there are some g/l accounts.I want to restrict the revenue node and some of the g/l accounts from that  node. When I restrict the InfoObject based on the Revenue node,I'm getting the correct result.But when I combine the revenue node with some g/l accounts ,It's giving the same result i.e. without filtering the g/l accounts.
    But in the workbook ,I can able to filter the query based on the g/l account.
    Now my question is how should I do the restriction in the query designer itself for getting values based on the g/l accounts
    Pls.let me know the solution, &
    I'll assign the points
    Thanks,
    Raji..

    Hello Srinivas,
    The Hierarchy for 0GLACCEXT is getting loaded from tables T011 & RFDT.
    Under this Hierarchy there will be many node.. Under each node there will be GL Accounts..
    If i am correct you want to restrict the query based on GL accounts in the query designer itself.
    the Infoprovider 0FIGL_VC2 contains 0GL_ACCOUNT, you can use that. Use 0GL_ACCOUNT in the Free Characteristics and attach variable to it.
    I hope this information will helps you..
    Thanks & Regards,
    NK.A
    Dont forget to assign points

  • Update Query using Toplink

    I would like to fire an update query using Toplink mapping objects. The
    structure of the Query would be like
    update <<table name>>
    set <<col name A>> = 'Y'
    where <<col name B>> in (<<valA>>,<<valB>>............);
    ValA, ValB.... are dynamic values passed from my front end Java App
    Can anyone help me in this regard...........
    Thanks
    Karthik

    Karthik,
    This is new functionality added in 10.1.3. You will want to look at UpdateAllQuery.
    Doug

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Can we rollback the update query using Transaction?

    Can we rollback the Update query by writing the update query with in the transaction, as i am implementing different update queries, sometimes I am mistakenly updating the table without where criteria, which is messing up the table. Is there anyway where
    we can write the update query within a transaction and rollback that particular update query which I am writing. I do have a backup table, but that wont be useful because we are doing lot of updates in a span of minutes. I researches about Apex Sql logs too,
    but we do not have access to download such tools. So, can anyone give me a good solution for this?

    Sure, if you use transaction like this
    begin transaction
    update 1
    update 2
    rollback transaction
    both updates will be rollbacked.
    If you want to always be sure about rows you're about to change, always first try with SELECT statement and put each individual UPDATE into separate transaction with rollback at the end, e.g.
    begin transaction
       select ... where some condition
       update . where same condition
       select ... where same condition to verify update
    rollback transaction
    If your last select showed correct info, change ROLLBACK into COMMIT and re-run that script again to perform the actual update.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Update record using SQL statement

    I have VB6.0 and Oracle 10G Express Edition in Windows 2000 Server. My procedure in VB 6.0 can't update record in the table using SQL statement, and the Error Message is " Missing SET keyword ".
    The SQL statement in VB6.0 look like this :
    General Declaration
    Dim conn as New ADODB.Connection
    Dim rs as New ADODB.Recordset
    Private Sub Command1_Click()
    dim sql as string
    sql = " UPDATE my_table " & _
    " SET Name = ' " & Text3.Text & " ' " & _
    " AND Unit = ' " & Text2.Text & " ' " & _
    " WHERE ID = ' " & Text1.Text & " ' "
    conn.Execute (sql)
    Private Sub Form Load()
    Set conn = New ADODB.Connection
    conn.Open "Provider=MSDASQL;" & "Data Source=my_table;"& "User ID =marketing;" & "Password=pass123;"
    I'm sorry about my language.
    What's wrong in my SQL statement, I need help ........ asap
    Best Regards,
    /Harso Adjie

    The syntax should be
    UPDATE TABLE XX
    SET FLD_1 = 'xxxx',
    FLD_2 = 'YYYY'
    WHERE ...
    'AND' is improperly placed in the SET.

  • Need help in this query using Case Statement

    I have the following query which is currently existing and I am adding few more conditions based on the new requirements which is based on a particular flag set as 1 or 0.
    If it is set to 1 then I should use the old query as it is and if it is set to 0 then I should add the new conditions.
    Basically when the flag is set to 0, I shouldnt be including some of the records that already exists and should include only new records. This is based on the plan_type_ids in (1,2,3,4).
    Hence I am using the Case statement to check if the plan_type_id is in (1,2) then do a set of not exists and if the plan_type_id in (3,4) then do set of not exists.
    But when I run this query it is giving me error. What am I doing wrong?
    Is there any other simple way to combine all the not exists for all of those select statements as given after the line ------------------------- into a single one?
    What am I doing wrong?
    I tried putting the NOT EXists before the case too but that too didnt work.
    Please help. Appreciate it.
    Thank you in advance.
    SELECT
    ee.employee_id
    ,'WELCOMEMSG'
    ,DECODE( me.member_enrollment_id
    ,first_enr.enrollment_id
    ,20
    ,23
    ) status_id
    ,me.member_enrollment_id
    ,wk.welcome_msg_id
    FROM wk
    ,employees ee
    ,MEMBER_ENROLLMENTS me
    ,plans pl
    ,( SELECT employee_id
    ,plan_type_id
    ,start_date
    ,plan_id
    ,MIN(MEMBER_ENROLLMENT_ID) member_enrollment_id
    FROM ( SELECT me.employee_id
    ,DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id
    ,pl.start_date
    ,wk.plan_id
    ,me.member_enrollment_id
    FROM wk
    ,PLANS pl
    ,MEMBER_ENROLLMENTS me
    WHERE wk.done_by = nvl('TEST' ,wk.done_by)
    AND wk.welcome_msg_name <> 'NONE'
    AND pl.employer_id = wk.employer_id
    AND wk.employer_id = 5
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
    AND pl.plan_id = NVL(wk.plan_id,pl.plan_id)
    AND me.plan_id = pl.plan_id
    AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
    AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
    MINUS
    SELECT me.employee_id
    ,DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id
    ,pl.start_date
    ,NULL plan_id
    ,me.member_enrollment_id
    FROM wk
    ,PLANS pl
    ,MEMBER_ENROLLMENTS me
    WHERE wk.done_by = nvl(NULL,wk.done_by)
    AND wk.welcome_msg_name <> 'NONE'
    AND pl.employer_id = wk.employer_id
    AND wk.employer_id = 5
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
    AND pl.plan_id = wk.plan_id
    AND me.plan_id = pl.plan_id
    AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
    AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
    WHERE employee_id = 100
    GROUP BY employee_id ,plan_type_id,start_date ,plan_id
    )first_enr
    ,MEMBER_EVENTS mv
    WHERE wk.done_by = nvl(NULL,wk.done_by)
    AND wk.employer_id = ee.employer_id
    AND ee.employee_id = me.employee_id
    AND ee.employee_id = 100
    AND me.plan_id = pl.plan_id
    AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
    AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
    AND is_expired(me.employee_id,me.plan_id) = 'Y'
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
    AND pl.plan_id=nvl(wk.plan_id,pl.plan_id)
    AND me.employee_id = first_enr.employee_id
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = first_enr.plan_type_id
    AND pl.start_date = first_enr.start_date
    AND me.member_enrollment_id = mv.member_enrollment_id (+)
    AND 'WELCOMEMSG' = mv.event_name(+)
    AND mv.member_enrollment_id IS NULL
    AND wk.welcome_msg_name <> 'NONE'
    AND NVL(first_enr.plan_id,0) = NVL( wk.plan_id,0)
    AND (FN_get_all_participant(wk.employer_id) = 1
    OR
    (FN_get_all_participant(wk.employer_id) = 0
    AND (CASE WHEN pl.plan_type_id IN (1,2)
    THEN NOT EXISTS (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = me.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date < pl.START_DATE
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id in (1, 2)
    UNION
    (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = me.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date = (pl.start_date - 365)
    \ AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id = wk.plan_type_id
    UNION
    (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = men2.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id = 2
    UNION
    (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = men2.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id = 1
    WHEN pl.plan_type_id IN (3, 4)
    THEN NOT EXISTS (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = men2.employee_id
    AND nvl(ma.account_end_date, sysdate) <= trunc(sysdate)
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date <= pl2.START_DATE
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id in (3, 4)
    END
    AND (CASE WHEN pl.plan_type_id IN (1,2)
    ERROR at line 89:
    ORA-00936: missing expression

    Maybe
    SELECT ee.employee_id,
           'WELCOMEMSG',
           DECODE(me.member_enrollment_id,first_enr.enrollment_id,20,23) status_id,
           me.member_enrollment_id,
           wk.welcome_msg_id
      FROM wk,
           employees ee,
           MEMBER_ENROLLMENTS me,
           plans pl,
           (SELECT employee_id,
                   plan_type_id,
                   start_date,
                   plan_id,
                   MIN(MEMBER_ENROLLMENT_ID) member_enrollment_id
              FROM (SELECT me.employee_id,
                           DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id,
                           pl.start_date,
                           wk.plan_id,
                           me.member_enrollment_id
                      FROM wk,
                           PLANS pl,
                           MEMBER_ENROLLMENTS me
                     WHERE wk.done_by = nvl('TEST',wk.done_by)  /* same as wk.done_by = 'TEST' */
                       AND wk.welcome_msg_name 'NONE'
                       AND pl.employer_id = wk.employer_id
                       AND wk.employer_id = 5
                       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
                       AND pl.plan_id = NVL(wk.plan_id,pl.plan_id)
                       AND me.plan_id = pl.plan_id
                       AND me.coverage_effective_date != NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
                       AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date,me.coverage_effective_date + 1)
                    MINUS
                    SELECT me.employee_id,
                           DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id,
                           pl.start_date,
                           NULL plan_id,
                           me.member_enrollment_id
                      FROM wk,
                           PLANS pl,
                           MEMBER_ENROLLMENTS me
                     WHERE wk.done_by = nvl(NULL,wk.done_by)  /* same as 1 = 1 */
                       AND wk.welcome_msg_name 'NONE'
                       AND pl.employer_id = wk.employer_id
                       AND wk.employer_id = 5
                       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
                       AND pl.plan_id = wk.plan_id
                       AND me.plan_id = pl.plan_id
                       AND me.coverage_effective_date NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
                       AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
             WHERE employee_id = 100
             GROUP BY employee_id,
                      plan_type_id,
                      start_date,
                      plan_id
           ) first_enr,
           MEMBER_EVENTS mv
    WHERE wk.done_by = nvl(NULL,wk.done_by)
       AND wk.employer_id = ee.employer_id
       AND ee.employee_id = me.employee_id
       AND ee.employee_id = 100
       AND me.plan_id = pl.plan_id
       AND me.coverage_effective_date != NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
       AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
       AND is_expired(me.employee_id,me.plan_id) = 'Y'
       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
       AND pl.plan_id = nvl(wk.plan_id,pl.plan_id)
       AND me.employee_id = first_enr.employee_id
       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = first_enr.plan_type_id
       AND pl.start_date = first_enr.start_date
       AND me.member_enrollment_id = mv.member_enrollment_id(+)
       AND 'WELCOMEMSG' = mv.event_name(+)
       AND mv.member_enrollment_id IS NULL
       AND wk.welcome_msg_name != 'NONE'
       AND NVL(first_enr.plan_id,0) = NVL(wk.plan_id,0)
       AND (
            FN_get_all_participant(wk.employer_id) = 1
        OR
            (FN_get_all_participant(wk.employer_id) = 0
       AND   NOT EXISTS(SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = me.employee_id
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date < pl.START_DATE
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id in (1,2)
                           and pl.plan_type_id IN (1,2)
                        UNION
                        SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = me.employee_id
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date = (pl.start_date - 365)
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id = wk.plan_type_id
                           and pl.plan_type_id IN (1,2)
                        UNION
                        SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = men2.employee_id
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id = (1,2)
                           and pl.plan_type_id IN (1,2)
                        UNION
                        SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = men2.employee_id
                           AND trunc(nvl(ma.account_end_date,sysdate)) <= trunc(sysdate)
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date <= pl2.START_DATE
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id in (3,4)
                           and pl.plan_type_id IN (3,4)
           )Regards
    Etbin

  • Update query using exists

    hi
    i am running the below query
    and i am ggetting the error
    update sh_mem a
    set a.custno=
    (select b.custno from ac_details b where to_number(a.memrefno)=b.memberno)
    where exists( select 1 from ac_details b where to_number(a.memrefno)=b.memberno)
    SQL> /
    set a.custno=
    ERROR at line 2:
    ORA-01407: cannot update
    ("TEST"."sh_mem"."CUSTNO") to NULL
    number of records from both the tables are not matching
    please help

    update sh_mem a
    set a.custno = (select distinct b.custno
    from ac_details b
    where to_number(a.memrefno)=b.memberno
    and a.cust_acctid=b.prd_acctid
    where exists( select 1
    from ac_details b
    where to_number(a.memrefno)=b.memberno
    and a.cust_acctid=b.prd_acctid
    ERROR at line 2:
    ORA-01407: cannot update
    ("TEST"."sh_mem"."CUSTNO") to NULL
    i even tried the following
    1 update sh_mem a
    2 set a.custno=
    3 nvl
    4 (
    5 (select b.custno from ac_details b where to_number(a.memrefno)=b.memberno)
    6 where exists( select 1 from ac_details b where to_number(a.memrefno)=b.memberno)
    7* ,a.custno)
    SQL> /
    nvl
    ERROR at line 3:
    ORA-00909: invalid number of arguments
    please help

  • Sender jdbc adapter....update query?

    Dear Team,
    we are selecting date from master database and client dont want to add any other field for update query.
    using select option, how to avoid selecting duplication records.
    can i use current date and time for selecting the records for every select statement?
    if yes then how to do it and what we need to update in update query??
    Regards,
    Chinna

    Hi Chinna,
    Check like this below.
    The following SQL statement selects the product name, and price for today from the "Products" table:
    SELECT ProductName, Price, Now() AS PerDate
    FROM Products;
    Similarly,
    UPDATE ProductName, Price, Now() AS PerDate
    FROM Products;
    Regards,
    Loordh.

  • How to run an update query on results from a spreadsheet

    Hey there,
    I am new to this kinda thing.
    I received a spreadsheet that has 2 tabs, 1 is called SQL Results, and has a ton of data. 1 is called SQL Statement and has a select statement in the first cell.
    I was told to run an update query using the spreadsheet, and was given this:
    = CONCATENATE("Update CARDMEMBERISSUE set CURRSTATUSCD = 'ACT', DATELASTMAINT = sysdate where AGREENBR = ",A2," and MEMBERNBR = ",B2," and ISSUENBR = ",C2,";")
    = CONCATENATE("Insert into CARDMEMBERISSUEHIST (AGREENBR, MEMBERNBR, ISSUENBR, EFFDATETIME, CARDSTATCD, STATREASON, DATELASTMAINT, DATESENT) values (",A2,",",B2,",",C2,",sysdate,'ACT',null,sysdate,null);"
    I am not sure what to do or how to run this.
    This is the what the lines in the spreadsheet look like, including column header, A1 is blank.
    A B C etc
         AGREE NBR      MEMBERNBR ISSUE NBR CURRSTATUSCD PREFIX CARD NBR AGREETYPCD OWNER PERS NBR     EXT CARD      ISSUE DATE     
    2     12          1     44     ISS g     22 22 19/10/2011

    The =concatenate bits are Excel formulae. Assuming they correctly written, they will generate a set of individual sql statements. The first concaenatewill generate a set of update statements against the CardMemberIssue table, and the seond will generate a set of insert statement to the CardMemberIssueHist table.
    You should be able to just paste the generated statements into whatever tool you are using to run sql to execute them. Before you do that though, make sure that you issue:
    alter session set cursor_sharing=force;before pasting anything in.
    john

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

  • Need help in this sql query to use Case Statement

    hi All,
    I have the below query -
    SELECT DISTINCT OFFC.PROV_ID
    ,OFFC.WK_DAY
    ,CASE
    WHEN OFFC.WK_DAY ='MONDAY' THEN 1
    WHEN OFFC.WK_DAY ='TUESDAY' THEN 2
    WHEN OFFC.WK_DAY ='WEDNESDAY' THEN 3
    WHEN OFFC.WK_DAY ='THURSDAY' THEN 4
    WHEN OFFC.WK_DAY ='FRIDAY' THEN 5
    WHEN OFFC.WK_DAY ='SATURDAY' THEN 6
    WHEN OFFC.WK_DAY ='SUNDAY' THEN 7
    END AS DOW
    ,OFFC.OFFC_OPENG_TIME
    ,OFFC.OFFC_CLSNG_TIME
    FROM GGDD.PROV_OFFC_HR OFFC
    WHERE OFFC.PROV_ID='0000600'
    WITH UR;
    this query is bringing results in 6 differnt rows with opening and closing time for each day separately. I want to generate the data in one row with each day having opening and closing time, so for 7 days, total 14 columns with opening and closing time. But i am not able to do that using case statement.
    can somebody help me in achieving that.
    thanks,
    iamhere

    Hi,
    Welcome to the forum!
    That's called a Pivot .
    Instead of having 1CASE expression, have 14, one for the opening and one for the closing time each day, and do GROUP BY to combine them onto one row.
    SELECT       OFFC.PROV_ID
    ,       MIN (CASE WHEN OFFC.WK_DAY ='MONDAY'    THEN OFFC.OFFC_OPENG_TIME END)     AS mon_opn
    ,       MIN (CASE WHEN OFFC.WK_DAY ='MONDAY'    THEN OFFC.OFFC_CLSNG_TIME END)     AS mon_cls
    ,       MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY'   THEN OFFC.OFFC_OPENG_TIME END)     AS tue_opn
    ,       MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY'   THEN OFFC.OFFC_CLSNG_TIME END)     AS tue_cls
    FROM        GGDD.PROV_OFFC_HR OFFC
    WHERE       OFFC.PROV_ID     = '0000600'
    GROUP BY  offc.prov_id
    ;This assumes there is (at most) only one row in the table for each distinct prov_id and weekday. If not, what do you want to do? Post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    The staement above works in Oracle 8.1 and up, but there's a better way (SELECT ... PIVOT) available in Oracle 11. What version are you using? (It's always a good idea to include this when you post a question.)
    Edited by: Frank Kulash on Jan 6, 2011 8:22 PM

  • Query Tuning - using CASE statement in the WHERE clause - Duplicate Post

    Duplicate Post by mistake.
    Please check
    Query Tuning - using CASE statement in the WHERE clause
    Edited by: Chaitanya on Jun 9, 2011 2:45 AM
    Edited by: Chaitanya on Jun 9, 2011 2:46 AM

    Duplicate Post by mistake.
    Please check
    Query Tuning - using CASE statement in the WHERE clause
    Edited by: Chaitanya on Jun 9, 2011 2:45 AM
    Edited by: Chaitanya on Jun 9, 2011 2:46 AM

  • I want single update query without use the function.

    I want to update sells_table selling_code field with max date product_code from product table.
    In product table there is multiple product_code date wise.
    I have been done it with below quey with the use of function but can we do it in only one update query
    without use the function.
    UPDATE sells_table
    SET selling_code = MAXDATEPRODUCT(ctd_vpk_product_code)
    WHERE NVL(update_product_flag,0) = 0 ;
    CREATE OR REPLACE FUNCTION HVL.maxdateproduct (p_product IN VARCHAR2) RETURN NUMBER
    IS
    max_date_product VARCHAR2 (100);
    BEGIN
    BEGIN
    SELECT NVL (TRIM (product_code), 0)
    INTO max_date_product
    FROM (SELECT product_code, xref_end_dt
    FROM product
    WHERE TO_NUMBER (p_product) = pr.item_id
    ORDER BY xref_end_dt DESC)
    WHERE ROWNUM = 1; -- It will return only one row - max date product code
    EXCEPTION
    WHEN OTHERS
    THEN
    RETURN 0;
    END;
    RETURN max_date_product;
    END maxdateproduct;
    Thanks in Advance.

    Hi,
    Something like this.
    update setlls_table st
            set selling_code =(select nvl(trim(product_code)) from 
                                  (select product_code
                                          , rank() over (partition by item_id order by xref_end_dt DESC) rn
                                       from product
                                   ) pr
                                   where rn =1
                                         and pr.item_id = st.ctd_vpk_product_code
                               ) where NVL(update_product_flag,0) = 0 ;As such not tested due to lack of input sample.
    Regards
    Anurag Tibrewal.

  • Using nested IIF expressions in an update query - is it possible?

    Hi everyone,
    I've been tasked by my manager to build a database which replicates a large, complicated Excel spreadsheet that consumes too much of our team's time and system resources. I've just about got most of it, but there is one particular required field that, in
    Excel, requires multi-layered nested If/Then formulae. I have to ask if building something similar in Access is possible. Here is the problem and the logic:
    Let us assume two established fields, Field 1 and Field 2; and then one field to be created via Update query, Field 3.
    Let us further assume that in Fields 1 and 2, there are three specific alphanumeric sequences occurring (“X1A”, “X1”, and “Z1”) that need to be identified and then called out as either “S1” or “U1” in field 3.
    If an Update Query were to be written to populate Field 3 with either “S1” or “U1” depending on one of the three alphanumeric sequences appearing in either Field 1 or Field 2, could it be written as the following expression, using the IIF and OR operators?
    And if so, is the syntax of the following expression correct?
    IIf([FIELD 1]="* X1A", "U1", OR IIf([FIELD 2]="* X1", "U1", OR IIf([FIELD 2]="* Z1", "U1", OR IIf([FIELD 1]="* X1", "U1", OR IIf([FIELD 1]="* Z1", "U1", "S1")))))
    Any help, critiques, or guidance would be appreciated.

    IMHO, a main consideration when "migrating" from Excel to Access is that a relational database is fundamentally different from a spreadsheet (although there can be much overlap).  In Excel, calculated values are "live" (unless you paste the values only
    into some other cells).  To replicate this "live" quality in Access, you can use a query with a calculation to display (not create or update) Field 3 in your case; Field 3 really wouldn't be a field, just a representation (query, form, report) or snapshot
    (export, print).  One reason for this is to avoid conflicts and redundancy.  In other words, if Field 3 is based solely on Fields 1 & 2 and some rule, then usually there is no need to waste disk space to store Field 3 and you don't risk Field
    3 being wrong as in the case when the rule changes.
    So here are a couple of options.
    1) Create view only query to display Field 3.  In query design view, enter the following where you would normally select a field:
    [FIELD 3]: IIf([FIELD 1]="* X1A", "U1", IIf([FIELD 2]="* X1", "U1", IIf([FIELD 2]="* Z1", "U1", IIf([FIELD 1]="* X1", "U1", IIf([FIELD 1]="* Z1", "U1", "S1")))))
    I assume you literally mean the asterisk character and are not trying to invoke a wildcard for the LIKE operator.
    There are other ways of doing this (e.g. with the LIKE operator or multiple queries and UNION), but I leave that up to you to explore.
    2) Actually update the value of FIELD 3 in a table.  Create two update queries and use your rules as conditions (i.e. the criteria in the bottom of query design).
    a) Update query 1 (run first): set [FIELD 3] = "U1" where [FIELD 1] = "* X1A" OR [FIELD 1] = "* X1" OR [FIELD 1] = "* Z1" OR [FIELD 2] = "* X1" OR [FIELD 2] = "* Z1"
    b) Update query 2 (run after): set [FIELD 3] = "S1" where [FIELD 3] is null
    Again, there are other ways of doing this such as setting the default value of [FIELD 3] in the table to "S1" and just running update query 1.
    Good luck.

Maybe you are looking for