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;

Similar Messages

  • 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

  • Why update query takes  long time ?

    Hello everyone;
    My update query takes long time.  In  emp  ( self testing) just  having 2 records.
    when i issue update query , it takes long time;
    SQL> select  *  from  emp;
      EID  ENAME     EQUAL     ESALARY     ECITY    EPERK       ECONTACT_NO
          2   rose              mca                  22000   calacutta                   9999999999
          1   sona             msc                  17280    pune                          9999999999
    Elapsed: 00:00:00.05
    SQL> update emp set esalary=12000 where eid='1';
    update emp set esalary=12000 where eid='1'
    * ERROR at line 1:
    ORA-01013: user requested cancel of current operation
    Elapsed: 00:01:11.72
    SQL> update emp set esalary=15000;
    update emp set esalary=15000
      * ERROR at line 1:
    ORA-01013: user requested cancel of current operation
    Elapsed: 00:02:22.27

    Hi  BCV;
    Thanks for your reply but it doesn't provide output,  please  see   this.
    SQL> update emp set esalary=15000;
    ........... Lock already occured.
    >> trying to trace  >>
    SQL> select HOLDING_SESSION from dba_blockers;
    HOLDING_SESSION
                144
    SQL> select sid , username, event from v$session where username='HR';
    SID USERNAME     EVENT
       144   HR    SQL*Net message from client
       151   HR    enq: TX - row lock contention
       159   HR    SQL*Net message from client
    >> It  does n 't  provide  clear output about  transaction lock >>
    SQL> SELECT username, v$lock.SID, TRUNC (id1 / POWER (2, 16)) rbs,
      2  BITAND (id1, TO_NUMBER ('ffff', 'xxxx')) + 0 slot, id2 seq, lmode,
      3  request
      4  FROM v$lock, v$session
      5  WHERE v$lock.TYPE = 'TX'
      6  AND v$lock.SID = v$session.SID
      7  AND v$session.username = USER;
      no rows selected
    SQL> select MACHINE from v$session where sid = :sid;
    SP2-0552: Bind variable "SID" not declared.

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

    Hi,
    I want to update the salary to 5000,for all the employees to whom the highest number of people report.
    Could any one help me on this.

    I agree with the solutions above...
    But, we dont know how your emp table is structured, I want to make a guess about your table structure and the query you might be looking for:
    This is open for discussion though...
    CREATE TABLE emp
       emp_id        NUMBER,
       emp_name      VARCHAR2 (100),
       emp_supv_id   NUMBER,
       emp_salary    NUMBER
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SALARY)
    VALUES
      (1, 'King', 1000);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (2, 'emp1', 1, 100);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (4, 'emp2', 1, 100);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (5, 'emp3', 1, 100);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (6, 'Minister', 1, 200);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (7, 'Soldier', 6, 10);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SALARY)
    VALUES
      (3, 'Queen', 1000);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (8, 'Maid', 3, 10);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (9, 'Maid1', 3, 10);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (10, 'Maid2', 3, 10);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (11, 'Soldier1', 6, 100);
    INSERT INTO SCOTT.EMP
      (EMP_ID, EMP_NAME, EMP_SUPV_ID, EMP_SALARY)
    VALUES
      (12, 'Maid3', 3, 10);
    COMMIT;input :
    emp_id      emp_name  emp_supv_id  emp_salary
    1     King          1000
    2     emp1     1     100
    4     emp2     1     100
    5     emp3     1     100
    6     Minister     1     200
    7     Soldier     6     10
    3     Queen          1000
    8     Maid     3     10
    9     Maid1     3     10
    10     Maid2     3     10
    11     Soldier1     6     100
    12     Maid3     3     10The update query follows...
    UPDATE emp
       SET emp_salary = 5000
    WHERE emp_id IN
              (WITH tmp AS
                       (    SELECT LPAD (' ', 2 * (LEVEL - 1)) || emp_id emp_id
                              FROM emp
                        START WITH emp_supv_id IS NULL
                        CONNECT BY PRIOR emp_id = emp_supv_id),
                    tmp1 AS
                       (SELECT a.*,
                               DENSE_RANK ()
                               OVER (PARTITION BY 1
                                     ORDER BY REGEXP_COUNT (emp_id, ' ') ASC)
                                  rnk
                          FROM tmp a)
               SELECT emp_id
                 FROM tmp1
                WHERE rnk = 1);
    commit; output :
    emp_id      emp_name  emp_supv_id  emp_salary
    1     King          5000
    2     emp1     1     100
    4     emp2     1     100
    5     emp3     1     100
    6     Minister     1     200
    7     Soldier     6     10
    3     Queen          5000
    8     Maid     3     10
    9     Maid1     3     10
    10     Maid2     3     10
    11     Soldier1     6     100
    12     Maid3     3     10Cheers,
    Manik

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

  • 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 can't update table

    Hi,
    During 1500-2000 concurrent users, DB Transaction locks occur. So that Update query can't update table and we get inconsistent data. How can we avoid this inconsistent data?? Why we get transaction locks??
    Eg. In update query it update the status of user with completed; but because of transaction lock  update query can't update status of user it remains uncompleted. So we can get wrong status of user(inconsistent data). Why UPDATE query update the status
    of user???
    update table set status='completed', date=@p2,score=@p3 where id=@p1

    You are not getting inconsistent data, you are getting the data according to the isolation level you are running under. The isolation level determines the locking model and therefore determines any bad dependencies you may experience. Reducing the bad dependencies
    through higher isolation level will lower concurrency. *This* is the core concept of Transactional Processing theory.
    Furthermore there is not really such a thing as a DB Transaction lock - at least not in the way you mean. SQL server does use DB locks (such as Shared transaction workspace and Exclusive transaction workspace) but the highest level of lock escalation is
    the object level (heap or btree) so those are the things you are really interested in. In the ideal would you want all Exclusive, Shared and U locks to be taken at the RID (heaps) or Key (cluster tables) level - and only have few of them per query.
    In conclusion think carefully about your query and how it is implimented under the covers by the database engine.
    Regards,
    Mark Broadbent.
    Microsoft Certified Master
    Contact me through twitter |
    blog | sqlcloud
    Please click "Propose as answer" if a post solves your problem
    or/and vote the post up if it's been helpful.

  • 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

  • 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

  • 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

  • True about updates through a view

    hi frds
    i just need the right answer for the choices mentioned below with explanation
    plz help me
    What is true about updates through a view?
    A. You cannot update a view with group functions.
    B. When you update a view group functions are automatically computed.
    C. When you update a view only the constraints on the underlying table will be in effect.
    D. When you update a view the constraints on the views always override the constraints on the underlying tables.

    And a very tricky only it is.
    Peter, you are correct that view constraints are not enforced in the sense of PKs and FKS, but there are two other view constraints that are enforced.
    SQL> CREATE TABLE t AS
      2  SELECT rownum id, object_name
      3  FROM all_objects
      4  WHERE rownum < 11;
    Table created.
    SQL> CREATE VIEW t_read AS
      2  SELECT * FROM t
      3  WITH READ ONLY;
    View created.
    SQL> CREATE VIEW t_check AS
      2  SELECT * FROM t
      3  WHERE mod(id,2) = 0
      4  WITH CHECK OPTION;
    View created.
    SQL> CREATE VIEW t_nocheck AS
      2  SELECT * FROM t
      3  WHERE MOD(id, 2) = 0;
    View created.
    SQL> INSERT INTO t_read VALUES (100, 'READ ONLY');
    INSERT INTO t_read VALUES (100, 'READ ONLY')
    ERROR at line 1:
    ORA-01733: virtual column not allowed here
    SQL> INSERT INTO t_check VALUES (100, 'EVEN ID');
    1 row created.
    SQL> INSERT INTO t_check VALUES (101, 'ODD ID');
    INSERT INTO t_check VALUES (101, 'ODD ID')
    ERROR at line 1:
    ORA-01402: view WITH CHECK OPTION where-clause violation
    SQL> INSERT INTO t_nocheck VALUES(100, 'EVEN ID');
    1 row created.
    SQL> INSERT INTO t_nocheck VALUES(101, 'ODD ID');
    1 row created.
    SQL> UPDATE t_check SET id = 201
      2  WHERE id = 2;
    UPDATE t_check SET id = 201
    ERROR at line 1:
    ORA-01402: view WITH CHECK OPTION where-clause violation
    SQL> UPDATE t_nocheck SET id = 201
      2  WHERE id = 2;
    1 row updated.The WITH READ ONLY constraint bars all changes to the view. The WITH CHECK OPTION stops any changes that would make the record invisible to the view. It is essentially a CHECK constraint on the view.
    John

  • I just updated my iPad 3 to ios 7.02 and can no longer sync with iTunes on my computer running OS 10.5.8. I'm wary about updating to Lion, which may cause any number of apps on my computer to no longer work. Although I may consider purchasing a new laptop

    I just updated my iPad to IOS 7.02 and unfortunately can no longer sync with my MacBook running OS 10.5.8. I'm wary about updating to Lion as this may cause any number of apps on my Macbook not to work at all or malfunction. Also my MacBook is 5 years old, and I was thinking about purchasing a new computer. I would like to decide when rather than be forced though. Does anyone have any suggestions for a work around? At the moment I do not subscribe to the cloud, and it looks like that is the only way I can back up my iPad now.

    Upgrade to Snow Leopard - it's compatible with the latest version of iTunes, and still supports PowerPC applications.
    $19.99 - http://store.apple.com/us/product/MC573Z/A/mac-os-x-106-snow-leopard
    Snow Leopard is required if you wanted to upgrade to Lion, anyway, which you may want to in the future if the latest version of iTunes no longer supports Snow Leopard.

Maybe you are looking for

  • How to Loop the Import of Excel Worksheets

    The following code goes to SharePoint, downloads a worksheet from the SharePoint, copies the worksheet to an existing workbook, then renames the downloaded worksheet. Public Sub ImportFileName()    ' Define Workbook and Worksheet Variables    Dim wkb

  • How to determine unused printers?

    Hi Community How can an administrator find out, which printers are in use and which are not? First idea was to check the spool, but we have to delete spooljobs very frequently (max 5-10 days left). Thanks for any ideas. Regards Michael

  • What Master Data to hold within a Data Warehouse

    Hi, We are developing a data warehouse which will incorporate Master Data entities. We have a pre-existing Master Data Management solution which will be the system of source for MD within the DW & associated Data Marts. We have decided to have a copy

  • Can't Uninstall Air, Mac OS X

    I started having major trouble with my Macbook Pro running OS X 10.6.7, after updating Adobe Flash and Air. I want to uninstall both, as a test. Flash was apparently uninstalled easily. No improvement. However, when I run the Adobe AIR Uninstaller.ap

  • How to load text file

    Dear All, How is it possible load a text file that contain SQL commands in the form and then execute the commands. Regards