Help in Update Statement

Hi All,
I would like to create an update statement which produces the desired result(below) but find that the update statement I have created does not perform.
<pre>
CREATE TABLE RACE(
S_ID NUMBER,
D_PID VARCHAR2(15),
OCCURENCE NUMBER);
</pre>
<pre>
insert into RACE
values(1,'HYD01',null);
insert into RACE
values(2,'HYD01',null);
insert into RACE
values(3,'HYD01',null);
insert into RACE
values(4,'HYD02',null);
insert into RACE
values(5,'HYD02',null);
insert into RACE
values(6,'HYD03',null);
</pre>
<pre>
CREATE TABLE RACE_LOOKUP_CNT AS
select d_pid,count(s_id)occurence
from race
GROUP BY d_pid;
</pre>
--Need to update the RACE table as
S_ID DPID OCCURENCE
1 HYD01 3
2 HYD01 3
3 HYD01 3
4 HYD02 2
5 HYD02 2
6 HYD03 1
Tried this subquery but kept getting multiple rows update.
<pre>
update RACE c
set
c.occurence = (
select (a.occurence)
from RACE_LOOKUP_CNT a
where a.occurence in
select occurence
from RACE b
AND a.d_pid =c.d_pid);
</pre>
Thank you all.

-Closed-

Similar Messages

  • Help on update statement in Apply DML Handler

    I followed the example given in Streams document.
    The document has the code for converting DELETE on the source to INSERT on the target. I added the dml handler code INSERT and UPDATE statements also.
    In DELETE, INSERT, UPDATE dml handler code, I am setting the command type to 'INSERT' so that I can insert the data in the target table.
    It is working fine for DELETE and INSERT statements.
    When I do update on the source table,
    I see only the value for the column I updated and all other columns are showing blank. May be this is the normal behaviour. How do I see the values for entire record. Do I need to join the source table based on the key column to get the data for the columns that were not updated.
    Also, I thought I should at least see the values for key column and updated column in the target table. It only shows the value for updated column but not for key column. But, When I choosed the old values (I know we need new values, but I just did it for test purpose) in the UPDATE DML handler, it shows the values for key column and the updated column.
    When I read the data in the LCR record using get_value('old', 'EMPLOYEE_ID') and get_value('NEW', 'FIRST_NAME')
    for key column, it shows the value in both old and new. I do not understand why it is not inserting the key column value in the target table.
    Thanks for your help in advance.
    Best regards,

    I forgot to mention these things.
    We added supplmental logging using alter database add supplemental log data (primary key, unique index) columns;
    I also added the supplemental logging on the source key column (employee_id) using ALTER TABLE emp ADD SUPPLEMENTAL LOG GROUP log_group_emp_pk (employee_id) ALWAYS;
    I also set the key column on the target table using DBMS_APPLY_ADM.SET_KEY_COLUMNS.
    Thanks for your help in advance.
    Best regards,

  • Need a help on Update statement

    Hi All,
    I Need a help in updating a table column. PFB my requirement.
    Table1
    ItemID OrgId       Date
    1       82     12/sep/2012   
    2       82     25/oct/2012
    3       82     17/Nov/2012
    4     82     22/Jan/2013
    5     82     26/sep/2012
    Table2
    Itemid     orgid       Date1
    1      82     23/sep/2012      
    2      82     25/Dec/2012
    3      82     17/Sep/2012
    4      82     22/Feb/2013
    5      82     26/Oct/2012
    Table3
    Itemid     orgid       Date3
    1      82     10/sep/2012      
    7      82     30/Dec/2012
    3      82     12/Sep/2012
    10      82     27/Feb/2013
    5      82     29/Oct/2012
    I Need to Update Date column of Table1 With Date3 of table3
    If
    Item and org combination is present in table3 and date column of table1 is less than Date3 of table3
    Else
    I need to Update with date2 of table2.Can we acheive this in a single update statement, can any one help me on this.
    Thanks and regards,
    Rakesh
    Edited by: Venkat Rakesh on Sep 27, 2012 11:04 PM

    You can probably also use MERGE:
    --DROP TABLE table1;
    --DROP TABLE table2;
    --DROP TABLE table3;
    ALTER SESSION SET nls_language = 'AMERICAN';
    CREATE TABLE table1
       itemid    CHAR (1),
       orgid     CHAR (2),
       thedate   DATE
    INSERT INTO table1   SELECT '1', '82', TO_DATE ('10/sep/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '2', '82', TO_DATE ('10/oct/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '3', '82', TO_DATE ('10/nov/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '4', '82', TO_DATE ('10/jan/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '5', '82', TO_DATE ('10/sep/2011', 'dd/mon/yyyy') FROM DUAL;-- won't be updated
    CREATE TABLE table2
       itemid    CHAR (1),
       orgid     CHAR (2),
       thedate   DATE
    INSERT INTO table2   SELECT '1', '82', TO_DATE ('01/sep/2012', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table2   SELECT '2', '82', TO_DATE ('01/dec/2012', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table2   SELECT '3', '82', TO_DATE ('01/sep/2012', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table2   SELECT '4', '82', TO_DATE ('01/feb/2012', 'dd/mon/yyyy') FROM DUAL;
    CREATE TABLE table3
       itemid    CHAR (1),
       orgid     CHAR (2),
       thedate   DATE
    INSERT INTO table3   SELECT '2', '82', TO_DATE ('30/dec/2009', 'dd/mon/yyyy') FROM DUAL; -- date less than table1, so picks from table2
    INSERT INTO table3   SELECT '4', '82', TO_DATE ('30/mar/2013', 'dd/mon/yyyy') FROM DUAL; -- larger than table1 , so pick this date
    -- table1 original data
    SELECT * FROM table1;
    -- merge new data
    MERGE INTO table1
         USING (SELECT NVL (t1.itemid, t2.itemid) itemid,
                       NVL (t1.orgid, t2.orgid) orgid,
                       t2.thedate prefdate ,
                       t1.thedate nextdate
                  FROM    table2 t1
                       FULL OUTER JOIN
                          table3 t2
                       ON t1.itemid = t2.itemid AND t1.orgid = t2.orgid) dat
            ON (dat.itemid = table1.itemid AND dat.orgid = table1.orgid)
    WHEN MATCHED
    THEN
       UPDATE SET table1.thedate = (case when prefdate > table1.thedate then prefdate else nextdate end) ;
    --table1 updated data
    SELECT * FROM table1;OUTPUT:
    Session altered.
    Table created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Table created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Table created.
    1 row created.
    1 row created.
    ITEMID ORGID THEDATE  
    1      82    10.09.2011
    2      82    10.10.2011
    3      82    10.11.2011
    4      82    10.01.2011
    5      82    10.09.2011
    5 rows selected.
    4 rows merged.
    ITEMID ORGID THEDATE  
    1      82    01.09.2012
    2      82    01.12.2012
    3      82    01.09.2012
    4      82    30.03.2013
    5      82    10.09.2011
    5 rows selected.

  • Need help with update statement with multiple joins

    I've got the following select statement that is pulling 29 records:
    SELECT
    PPA.PROJECT_ID,
    PPA.SEGMENT1,
    peia.expenditure_item_id,
    peia.expenditure_type,
    pec.expenditure_comment
    FROM PA.PA_PROJECTS_ALL PPA,
    pa.pa_expenditure_items_all peia,
    pa.pa_expenditure_comments pec
    where PPA.segment1 < '2008' and
    PPA.project_id = 52 and -- just run for project # 20077119 for testing
    peia.expenditure_type = 'PAYROLL' and
    peia.project_id = ppa.project_id and
    PEC.EXPENDITURE_ITEM_ID = PEIA.EXPENDITURE_ITEM_ID;
    I need to update the pec.expenditure_comments to a static field for those 29 records. I assume I should start with the following, but not sure how to complete the where:
    update
    pa.pa_expenditure_comments pec
    set pec.expenditure_comment = 'REFERENCE HD#728'
    where
    First time that we've ever needed to update, so any and all help appreciated.

    Try using exists:
    update pa.pa_expenditure_comments pec
    set    pec.expenditure_comment = 'REFERENCE HD#728'
    where exists ( select null
                   from   pa.pa_projects_all ppa
                   ,      pa.pa_expenditure_items_all peia
                   ,      pa.pa_expenditure_comments pec2
                   where  ppa.segment1 < ''    -- not sure what you posted here, so for next time:
                                               -- please put your examples between the code tags.
                   and    ppa.project_id = 52  -- just run for project # 20077119 for testing
                   and    peia.expenditure_type = 'PAYROLL'
                   and    peia.project_id = ppa.project_id
                   and    pec2.expenditure_item_id = peia.expenditure_item_id
                   and    pec2.expenditure_item_id = pec.expenditure_item_id
                 );

  • Help on update statement

    Hi, Please help me on the following update scenario
    I have a column in a table PRD_NM which is a not null column.. I want to update this column with a set of values from another query..
    UPDATE Table1 tg
    set PRD_NM=(select PRD_NM from( select prd_nm,state,item_no,bar_code from products) sr
    where tg.state=sr.state and tg.item_no=sr.item_no and tg.bar_code=sr.bar_code
    and tg.PRD_NM='NA')
    basically i want to update all those PRD_NM with value 'NA' to the value coming from the source query...
    but when I run the statement I am getting an error saying that the PRD_NM cannot be set to null... But here I am not considering anything that can be a null when updated.
    Please help with any idea...
    Edited by: user626688 on Jan 21, 2009 11:18 AM

    Hi,
    If you can't UPDATE via an in-line view (as Someoneelse suggested), and you don't want to basically do the same query twice (once in the scalar sub-query, then again in an EXISTS subquery, as in Someoneelse's next to last message), you can use MERGE:
    MERGE INTO     Table1     tg
    USING     (     SELECT     prd_nm, state, item_no, bar_code
              FROM     products
         )          sr
    ON     (     tg.state     = sr.state
         AND     tg.item_no     = sr.item_no
         AND     tg.bar_code     = sr.bar_code
         AND     tg.PRD_NM     = 'NA'
    WHEN MATCHED THEN
         UPDATE     SET     tg.prd_nm     = sr.prd_nm;Without copies of your tables and data, I can't test.

  • Need help in update statement

    hi,
    how can i achieve the following logic
    I have table ABC with column A varchar(20), B(int), C(varchar(20))
    if A is null and B is valid number then C has to be updated with 'text'
    if A is valid text and B is null then C has to be updated with 'number'
    if A is valid text and B is valid number then C has to be updated with 'text-number'
    thanks in advance

    First Update
    UPDATE ABC
    SET C= 'text'
    where A is null;since B is int data type it will always storeintegeres hence check not required.
    Second Update
    UPDATE ABC
    set C = 'number'
    where A is not null
    and B IS NULLThird Update
    UPDATE ABC
    SET C = 'number-text'
    WHERE A IS NOT NULL;Hope this answers.
    You can get this in single update too
    AND B IS NOT NULL

  • Help with update statement

    Create table temp_sibs as
    (select 1701 sib_1, 1702 sib_2 from dual
    union all
    select 1171,1172 from dual
    union all
    select 1701,1172 from dual
    union all
    select 1171,1174 from dual
    union all
    select 1173,1176 from dual
    union all
    select 2001,2004 from dual
    union all
    select 2001,2006 from dual
    union all
    select 2002,2006
    from dual)
    create table temp_sib_data as
    (select 111 pid, 1701 sibid, 5 amt from dual
    union all
    select 111 pid, 1176 sibid, 5 from dual
    union all
    select 222 pid, 2006 sibid, 5 from dual
    union all
    select 333 pid, 2001 sibid, 5 from dual
    union all
    select 333 pid, 2002 sibid, 5 from dual
    union all
    select 333 pid, 1171 sibid, 5 from dual
    First table is a lookup table that defines relationships sib_1 is related to sib_2
    Second table consists of a column pid and column sibid which is either sib_1 or sib_2
    The user would pass parameter pid and sibid and I want to update all the related rows with any matching sibid to 0.
    It is like 1701 matches with 1702 and 1701 matches with 1174 so indirectly 1701 and 1174 match...and 1171 matches because
    1171 matches with 1174
    so all 1701,1702,1171,1172, 1173,1174,1176 match (indirectly with each other)
    So for example if the user passes 333 pid and 2001 rows with 333,2001 and 333,2002 should update the amt to 0
    and if the user passes 111 and 1176 than 1st 2 rows should be updated to 0.

    Hi,
    try this:
    DEFINE PID='333'
    DEFINE sibid='2001'
    -- SELECT is only for test.
    -- Replace SELECT with: UPDATE TEMP_SIB_DATA SET AMT = 0
    SELECT * FROM TEMP_SIB_DATA  
    WHERE  PID = &PID   AND  SIBID IN (
           WITH TEMP AS(
                SELECT SIB_1, SIB_2 FROM TEMP_SIBS
                   START WITH     SIB_1 = &&SIBID   OR  SIB_2 = &&SIBID
                   CONNECT BY NOCYCLE      PRIOR SIB_2 = SIB_1  
                                       OR  PRIOR SIB_1 = SIB_2  
                                       OR  SIB_2 = PRIOR SIB_2  
                                       OR  SIB_1 = PRIOR SIB_1
            SELECT SIB_1 FROM TEMP
            UNION ALL
            SELECT SIB_2 FROM TEMP
    );For pid=333 and sibid=2001 it returns desired records for update:
    PID                    SIBID                  AMT                   
    333                    2001                   5
    333                    2002                   5For pid=111 and=1176 it returns one row - 1176 matches only with 1173 and 1173 doesn't match with any other rows,
    so only 5th row, not first 2, should be updated ... maybe I missed something ?
    PID                    SIBID                  AMT
    111                    1176                   5

  • Need help to write a query for Update statement with  join

    Hi there,
    The following update statement gives me error as the given table in set statement is invalid. But its the right table .
    Is the statement correct? Please help .
    update (
           select distinct(vpproadside.VEHICLE_CRED_OVERRIDE.vin)            
             from vpproadside.VEHICLE_CRED_OVERRIDE
             join vpproadside.vpp_vehicle
               on vpproadside.vpp_vehicle.vin = vpproadside.VEHICLE_CRED_OVERRIDE.vin
            where VPP_CARRIER_SEQ_NUMBER = 90
              and EXPIRY_DATE = '17-MAR-10'
       set vpproadside.VEHICLE_CRED_OVERRIDE.EXPIRY_DATE = '15-SEP-10';Edited by: Indhu Ram on Mar 12, 2010 1:00 PM
    Edited by: Indhu Ram on Mar 12, 2010 1:22 PM
    Edited by: Indhu Ram on Mar 12, 2010 2:35 PM
    Edited by: Indhu Ram on Mar 15, 2010 8:04 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:06 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:28 AM

    Ask Tom has very good discussion about this, if UPDATE does not work for PK issue, you can use MERGE
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:760068400346785797

  • How to use a update statement which has a string containing '&' -  Pls help

    When used the following select statment in SQL plus it is working fine:
    SELECT * FROM REDEMPTION_OFFERS
    WHERE portfolio=203 AND display_description= '$100 Bed Bath'||' & '||'Beyond Gift Card' AND ext_redemption_type_lc = 'ERT_CERT'
    But when using the same statement in a Update statement it is not working. Can some one please help me: Thanks in advance
    UPDATE REDEMPTION_OFFERS SET LONG_DESCRIPTION = 'null'
    WHERE portfolio=203 AND display_description= '$100 Bed Bath'||' & '||'Beyond Gift Card' AND ext_redemption_type_lc = 'ERT_CERT'

    When used the following select statment in SQL plus
    it is working fine:
    SELECT * FROM REDEMPTION_OFFERS
    WHERE portfolio=203 AND display_description= '$100
    Bed Bath'||' & '||'Beyond Gift Card' AND
    ext_redemption_type_lc = 'ERT_CERT'
    But when using the same statement in a Update
    statement it is not working. Can some one please
    help me: Thanks in advance
    UPDATE REDEMPTION_OFFERS SET LONG_DESCRIPTION =
    'null'
    WHERE portfolio=203 AND display_description= '$100
    Bed Bath'||' & '||'Beyond Gift Card' AND
    ext_redemption_type_lc = 'ERT_CERT'looks like You are using the UPDATE statement in SQL*PLUS too. Your statement is also working....
    SQL> select * from a;
            F1 F2        F3
             1           BED BATH
             2           BED BATH
             5           BED BATH
             3           BED BATH
            -2           BED BATH
            -4           BED BATH
            -1           BED BATH
    7 rows selected.
    SQL> update a set f3 = 'BED '||'&'||' BATH';
    7 rows updated.
    SQL> select * from a;
            F1 F2        F3
             1           BED & BATH
             2           BED & BATH
             5           BED & BATH
             3           BED & BATH
            -2           BED & BATH
            -4           BED & BATH
            -1           BED & BATH
    7 rows selected.

  • Sender JDBC: help to construct Update statement

    Hi,
    I need help in writing a update statement to DB2 database in sender JDBC adapter.
    The sender adapter picks up only few records say 10 at a time which match the Select query condition. So I would need to update only those selected "n" records and not all the records that match the Select query condition.
    Select looks like :
    Select * from <table> where <condition> fetch first <n> rows only.
    But it is not allowing the following update
    update <table> set <field> = <value> where <field> IN (Select * from <table> where <condition> fetch first <n> rows only)
    The above statement errors because DB2 does not allows u201CFetchu201D statement within the update sub query.
    Any pointers to a write update statement for n records is highly appreciatedu2026
    ~SaNvu2026

    Hi Santosh,
    In JDBC Sender Adapter provide the following select & update statements
    Select Statement:
    select * from <table> where <condition> AND ROWNUM<N (N==No.of Rows)
    Update Statement:
    update <table> set <field> = <value> where <field> IN (Select * from <table> where <condition> AND ROWNUM<N)
    (N==No.of Rows)
    And for the error you are facing is because of the server communication link failure between the two systems.
    Check the connections and try to stop & start communication channels once.
    Regards
    Venkat Rao .G

  • Help with doing SELECT sub query within the SET of an UPDATE statement

    After doing some research, it appears as if it's possible to use a SELECT subquery in the SET of an UPDATE statement.  i did find some examples and here is my code, however when I click the "check" button it's saying the field (my entire select subquery) is unknown and neither in one of the specified tables or defined by a "DATA".  Do I have a syntax issue or is there another reason why it's not taking this as a valid statement?  Thanks for the help!
    LOOP AT IT_DATA
    UPDATE /BIC/AZDP_O0140
       SET /BIC/ZCOUNTER = (SELECT COUNT( DISTINCT MATERIAL )
                            FROM /BIC/AZDP_O0140
                            WHERE MATERIAL EQ IT_DATA-MATERIAL
                            GROUP BY MATERIAL).
    ENDLOOP.

    my Update does indeed have a WHERE clause but because of the issue i'm having, all my criteria in my WHERE is black text in the ABAP editor.  The editor doesn't even recognize the keywords "WHERE" or "EQ".  Below is my entire statement which contains all WHERE criteria in both the Update and the Subquery, i've just removed it for testing to help simplify the query and eliminate as many other factors as posisble that may be causing problems:
    LOOP AT IT_DATA.
       UPDATE /BIC/AZDP_O0140
       SET /BIC/ZCOUNTER = (SELECT COUNT( DISTINCT MATERIAL ) FROM /BIC/AZDP_O0140
       WHERE WHSE_NUM EQ IT_DATA-WAREHOUSE
        AND  PLANT EQ IT_DATA-PLANT
        AND  /BIC/ZTRAN_NO EQ IT_DATA-TRANS_NUM
        AND  DELIV_NUMB EQ IT_DATA-DELIVERY
        AND  MATERIAL EQ IT_DATA-MATERIAL
        GROUP BY MATERIAL)
       WHERE WHSE_NUM EQ IT_DATA-WAREHOUSE
        AND  PLANT EQ IT_DATA-PLANT
        AND  /BIC/ZTRAN_NO EQ IT_DATA-TRANS_NUM
        AND  DELIV_NUMB EQ IT_DATA-DELIVERY
        AND  MATERIAL EQ IT_DATA-MATERIAL.
    ENDLOOP.
    i should also mention the sources i found were not within the SAP Library but instead on other third-party ABAP websites.  so because i was having issues i wanted to post here to see if anyone else has come up with a working solution.  but if this cannot be done i can likely come up with a solution for my needs using multiple internal tables, this would just have been much easier since i can get a query like this to do what i want in SQL Server.  Thought i could utilize this in ABAP as well.

  • Update Statement Help Please

    I'm coming from the MS SQL world LOL
    and Im trying to write an update statement but in Oracle there is no INNER JOIN.
    Can you give me some advice on how to do this please?
    UPDATE employee
    SET employee.name = tmpuser.name
    FROM employee
    INNER JOIN tmpuser
    on tmpuser.emp_id = employtee.emp_id
    Thank you for you help.
    P

    Hi,
    AJR wrote:
    Frank,
    But when we are using the where condition it should update records with the matching ids. right?What your query should do is entirely up to you; I can't answer any questions about that, only you can.
    I have faced this issue earlier.
    WHERE       tmpuser.emp_id = employee.emp_idCan you explain?Not out of context. Post a complete statement.
    If this isn't directly related to user9170886's problem, then it's better to start your own thread.
    I can say a few things about UPDATE statements in general:
    The WHERE clause governs which rows will be UPDATEd. If there is no WHERE clause, all rows in the table will be UPDATEd.
    So
    UPDATE     employee
    SET     employee_name = ( <subquery> )
    ;UPDATEs every row in employee, because the UPDATE statement does not have a WHERE clause. Nothing in the sub-query can change that.
    A sub-query can reference values from its immediate parent, but a parent can't reference values from a sub-query (other than the values actually returned by the sub-query, of course).
    So
    UPDATE     employee
    SET     employee_name = ( <subquery> )
    WHERE     tmpuser.emp_id     = employee.emp_id
    ;causes an error, because there is no table called tmpuser in the main UPDATE statement. Nothing in the sub-query can change that.

  • Update statement help

    Hello folks,
    I need some help/advise on an UPDATE statement.
    I have two tables. I need to join these tables and update a field in table1 with a field from table2.
    Please see the attached jpg file.
    The first 3 coloumns are from table1 and last 2 columns in the picture are from table2.
    I want to update NEXT_RATE_RESET_ADJ_P field (from table1) with NEXT_RESET_DATE_ADJUSTED field (from table2). I want to join them between table1.DEAL_LEG_ID_P and table2.DEAL_LEG_ID.
    I have never written update statement with a join in it.
    Any help is greatly appreciated.

    UPDATE EMP1
    SET EMP1.SAL =
    (SELECT EMP2.SAL
    FROM EMP2
    WHERE EMP1.EMPNO = EMP2.EMPNO
    AND EMP1.DEPTNO = EMP2.DEPTNO)
    WHERE EMP1.JOB = 'SALESMAN';
    To avoid setting EMP1.SAL to NULL if there is no matching EMP2 record
    UPDATE EMP1
    SET EMP1.SAL =
    (SELECT EMP2.SAL
    FROM EMP2
    WHERE EMP1.EMPNO = EMP2.EMPNO
    AND EMP1.DEPTNO = EMP2.DEPTNO)
    WHERE EMP1.JOB = 'SALESMAN'
    AND EXISTS (SELECT NULL
    FROM EMP2
    WHERE EMP1.EMPNO = EMP2.EMPNO
    AND EMP1.DEPTNO = EMP2.DEPTNO);

  • Help needed with Update statements.

    Hello All,
    I am trying to learn Berkeley XMLDB and facing problem to query the inserted XML file. I have a small XML file with the following contents:
    &lt;?xml version="1.0" standalone="yes"?&gt;
    &lt;Bookstore&gt;
    &lt;Book&gt;
    &lt;book_ID&gt;1&lt;/book_ID&gt;
    &lt;title&gt;Harry Potter and the Order of the Phoenix&lt;/title&gt;
    &lt;subtitle&gt;A Photographic History&lt;/subtitle&gt;
    &lt;author&gt;
    &lt;author_fname&gt;J.K.&lt;/author_fname&gt;
    &lt;author_lname&gt;Rowling&lt;/author_lname&gt;
    &lt;/author&gt;
    &lt;price&gt;9.99&lt;/price&gt;
    &lt;year_published&gt;2004&lt;/year_published&gt;
    &lt;publisher&gt;Scholastic, Inc.&lt;/publisher&gt;
    &lt;genre&gt;Fiction&lt;/genre&gt;
    &lt;quantity_in_stock&gt;28997&lt;/quantity_in_stock&gt;
    &lt;popularity&gt;20564&lt;/popularity&gt;
    &lt;/Book&gt;
    &lt;/Bookstore&gt;
    When I try to update the TITLE of this node I have the following error message:
    C:\Users\Chandra\Desktop\BDB&gt;javac -classpath .;"C:\Program Files\Sleepycat Soft
    ware\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\B
    erkeley DB XML 2.1.8\jar\db.jar" bdb.java
    bdb.java:75: illegal start of expression
    public static final String STATEMENT1 = "replace value of node collection("twopp
    ro.bdbxml")/Bookstore/Book/bookid/title with 'NEWBOOK'";
    ^
    bdb.java:80: ')' expected
    System.out.println("Done query: " + STATEMENT1);
    ^
    2 errors
    But when I remove the update statements and just try to display the TITLE of this node, I dont see any outputs. Please help me to catch up with my mistakes. Below is source code I am using to run this functionality.
    Thanks.
    import java.io.File;
    import java.io.FileNotFoundException;
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.Environment;
    import com.sleepycat.db.EnvironmentConfig;
    import com.sleepycat.dbxml.XmlContainer;
    import com.sleepycat.dbxml.XmlException;
    import com.sleepycat.dbxml.XmlInputStream;
    import com.sleepycat.dbxml.XmlManager;
    import com.sleepycat.dbxml.XmlUpdateContext;
    import com.sleepycat.dbxml.XmlDocument;
    import com.sleepycat.dbxml.XmlQueryContext;
    import com.sleepycat.dbxml.XmlQueryExpression;
    import com.sleepycat.dbxml.XmlResults;
    import com.sleepycat.dbxml.XmlValue;
    public class bdb{
    public static void main(String[] args)
    Environment myEnv = null;
    File envHome = new File("D:/xmldata");
    try {
    EnvironmentConfig envConf = new EnvironmentConfig();
    envConf.setAllowCreate(true); // If the environment does not
    // exits, create it.
    envConf.setInitializeCache(true); // Turn on the shared memory
    // region.
    envConf.setInitializeLocking(true); // Turn on the locking subsystem.
    envConf.setInitializeLogging(true); // Turn on the logging subsystem.
    envConf.setTransactional(true); // Turn on the transactional
    envConf.setRunRecovery(true);
    // subsystem.
    myEnv = new Environment(envHome, envConf);
    // Do BDB XML work here.
    } catch (DatabaseException de) {
    // Exception handling goes here
    } catch (FileNotFoundException fnfe) {
    // Exception handling goes here
    } finally {
    try {
    if (myEnv != null) {
    myEnv.close();
    } catch (DatabaseException de) {
    // Exception handling goes here
    XmlManager myManager = null;
    XmlContainer myContainer = null;
    // The document
    String docString = "D:/xmldata/test.xml";
    // The document's name.
    String docName = "cia";
    try {
    myManager = new XmlManager(); // Assumes the container currently exists.
    myContainer =
    myManager.createContainer("twoppro.bdbxml");
    myManager.setDefaultContainerType(XmlContainer.NodeContainer); // Need an update context for the put.
    XmlUpdateContext theContext = myManager.createUpdateContext(); // Get the input stream.
    XmlInputStream theStream =
    myManager.createLocalFileInputStream(docString); // Do the actual put
    myContainer.putDocument(docName, // The document's name
    theStream, // The actual document.
    theContext, // The update context
    // (required).
    null); // XmlDocumentConfig object
    theStream.delete();
    // Update the title
    public static final String STATEMENT1 = "*replace value of node collection("twoppro.bdbxml")/Bookstore/Book/[bookid=1]/title with 'NEWBOOK'";*
    XmlQueryContext context = myManager.createQueryContext();
    XmlQueryExpression queryExpression1 = myManager.prepare(STATEMENT1, context);
    System.out.println("Try to execute query: " +
    System.out.println("Done query: " + STATEMENT1);
    queryExpression1.execute(context);
    // Get a query context
    XmlQueryContext context = myManager.createQueryContext();
    // Set the evaluation type to Lazy.
    context.setEvaluationType(XmlQueryContext.Lazy);
    // Declare the query string
    String queryString =
    "for $u in collection('twoppro.dbxml')/Bookstore/Book/[bookid=1]"
    + "*return $u/title";*
    // Prepare (compile) the query
    XmlQueryExpression qe = myManager.prepare(queryString, context);
    XmlResults results = qe.execute(context);
    System.out.println("ok");
    System.out.println(results);
    } catch (XmlException e) {
    // Error handling goes here. You may want to check
    // for XmlException.UNIQUE_ERROR, which is raised
    // if a document with that name already exists in
    // the container. If this exception is thrown,
    // try the put again with a different name, or
    // use XmlModify to update the document.
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } finally {
    try {
    if (myContainer != null) {
    myContainer.close();
    if (myManager != null) {
    myManager.close();
    } catch (XmlException ce) {
    // Exception handling goes here

    Thanks Rucong. The change you suggested did helped me to run the program correct. But I also have the display function to retrive the results and my program is parsed without any output.
    C:\Users\C\Desktop\BDB&gt;Clientbuild.bat
    C:\Users\C\Desktop\BDB&gt;javac -classpath .;"C:\Program Files\Sleepycat Soft
    ware\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\B
    erkeley DB XML 2.1.8\jar\db.jar" bdb.java
    C:\Users\C\Desktop\BDB&gt;Client.bat
    C:\Users\C\Desktop\BDB&gt;java -classpath .;"C:\Program Files\Sleepycat Softw
    are\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\Be
    rkeley DB XML 2.1.8\jar\db.jar" bdb
    See there is no OUPUT displayed. Is there somethinglike a 'print' I have to use in this java code.
    Any ideas ? Below is the code I am using now
    import java.io.File;
    import java.io.FileNotFoundException;
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.Environment;
    import com.sleepycat.db.EnvironmentConfig;
    import com.sleepycat.dbxml.XmlContainer;
    import com.sleepycat.dbxml.XmlException;
    import com.sleepycat.dbxml.XmlInputStream;
    import com.sleepycat.dbxml.XmlManager;
    import com.sleepycat.dbxml.XmlUpdateContext;
    import com.sleepycat.dbxml.XmlDocument;
    import com.sleepycat.dbxml.XmlQueryContext;
    import com.sleepycat.dbxml.XmlQueryExpression;
    import com.sleepycat.dbxml.XmlResults;
    import com.sleepycat.dbxml.XmlValue;
    public class bdb{
    public static void main(String[] args)
    Environment myEnv = null;
    File envHome = new File("D:/xmldata");
    try {
    EnvironmentConfig envConf = new EnvironmentConfig();
    envConf.setAllowCreate(true); // If the environment does not
    // exits, create it.
    envConf.setInitializeCache(true); // Turn on the shared memory
    // region.
    envConf.setInitializeLocking(true); // Turn on the locking subsystem.
    envConf.setInitializeLogging(true); // Turn on the logging subsystem.
    envConf.setTransactional(true); // Turn on the transactional
    envConf.setRunRecovery(true);
    // subsystem.
    myEnv = new Environment(envHome, envConf);
    // Do BDB XML work here.
    } catch (DatabaseException de) {
    // Exception handling goes here
    } catch (FileNotFoundException fnfe) {
    // Exception handling goes here
    } finally {
    try {
    if (myEnv != null) {
    myEnv.close();
    } catch (DatabaseException de) {
    // Exception handling goes here
    XmlManager myManager = null;
    XmlContainer myContainer = null;
    // The document
    String docString = "D:/xmldata/test.xml";
    // The document's name.
    String docName = "cia";
    try {
    myManager = new XmlManager(); // Assumes the container currently exists.
    myContainer =
    myManager.createContainer("twoppro.bdbxml");
    myManager.setDefaultContainerType(XmlContainer.NodeContainer); // Need an update context for the put.
    XmlUpdateContext theContext = myManager.createUpdateContext(); // Get the input stream.
    XmlInputStream theStream =
    myManager.createLocalFileInputStream(docString); // Do the actual put
    myContainer.putDocument(docName, // The document's name
    theStream, // The actual document.
    theContext, // The update context
    // (required).
    null); // XmlDocumentConfig object
    theStream.delete();
    // Update the title
    String STATEMENT1 = "for $n in collection('twoppro.bdbxml')/Bookstore/Book[book_ID=1]/title return replace value of node $n with 'NEWBOOK'";
    XmlQueryContext context = myManager.createQueryContext();
    XmlQueryExpression queryExpression1 = myManager.prepare(STATEMENT1, context);
    System.out.println("Done query: " + STATEMENT1);
    queryExpression1.execute(context);
    // Get a query context
    XmlQueryContext thiscontext = myManager.createQueryContext();
    // Set the evaluation type to Lazy.
    context.setEvaluationType(XmlQueryContext.Lazy);
    // Declare the query string
    String queryString =
    "for $u in collection('twoppro.dbxml')/Bookstore/Book/[bookid=1]"
    + "return $u/title";
    // Prepare (compile) the query
    XmlQueryExpression qe = myManager.prepare(queryString, thiscontext);
    XmlResults results = qe.execute(thiscontext);
    System.out.println("ok");
    System.out.println(results);
    } catch (XmlException e) {
    // Error handling goes here. You may want to check
    // for XmlException.UNIQUE_ERROR, which is raised
    // if a document with that name already exists in
    // the container. If this exception is thrown,
    // try the put again with a different name, or
    // use XmlModify to update the document.
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } finally {
    try {
    if (myContainer != null) {
    myContainer.close();
    if (myManager != null) {
    myManager.close();
    } catch (XmlException ce) {
    // Exception handling goes here
    Thanks.

  • Help with this update statement..

    Hi everyone,
    I am trying to update a column in a table .I need to update that column
    with a function that takes patient_nbr and type_x column values as a parameter.
    That table has almost "300,000" records. It is taking long time to complete
    almost 60 min to 90 min.
    Is it usual to take that much time to update that many records?
    I dont know why it is taking this much time.Please help with this update statement.
    select get_partner_id(SUBSTR(patient_nbr,1,9),type_x) partner_id from test_load;
    (it is just taking 20 - 30 sec)
    I am sure that it is not the problem with my function.
    I tried the following update and merge statements .Please correct me if i am wrong
    in the syntax and give me some suggestions how can i make the update statement fast.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    there is a index on patient_nbr column
    and the statistics are gathered on this table.

    Hi Justin,
    As requested here are the explain plans for my update statements.Please correct if i am doing anything wrong.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 3793814442"
    "| Id  | Operation          | Name             | Rows  | Bytes | Cost (%CPU)| Time     |"
    "|   0 | UPDATE STATEMENT   |                  |   274K|  4552K|  1488   (1)| 00:00:18 |"
    "|   1 |  UPDATE            |        TEST_LOAD |       |       |            |          |"
    "|   2 |   TABLE ACCESS FULL|        TEST_LOAD |   274K|  4552K|  1488   (1)| 00:00:18 |"
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 1188928691"
    "| Id  | Operation            | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |"
    "|   0 | MERGE STATEMENT      |                  |   274K|  3213K|       |  6660   (1)| 00:01:20 |"
    "|   1 |  MERGE               |        TEST_LOAD |       |       |       |            |          |"
    "|   2 |   VIEW               |                  |       |       |       |            |          |"
    "|*  3 |    HASH JOIN         |                  |   274K|    43M|  7232K|  6660   (1)| 00:01:20 |"
    "|   4 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|  4017K|       |  1482   (1)| 00:00:18 |"
    "|   5 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|    40M|       |  1496   (2)| 00:00:18 |"
    "Predicate Information (identified by operation id):"
    "   3 - access("A"."patient_nbr"="patient_nbr")"Please give some suggestions..
    what's the best approach for doing the updates for huge tables?
    Thanks

Maybe you are looking for

  • Line 1: Supplier 0000100405 not intended for purch. org

    Hi All, I am facing one issue in shopping cart, when i clicked on check button, system throwing an error as "Line 1: Supplier 0000100405 not intended for purch. org" I have replicated this vendor from ECC & have given the right vendor root org while

  • Can anyone help? I have downloaded and installed the QuickTime MPEG-2 Component but it doesn't work.

    I purchased the QuickTime MPEG-2 component for Quicktime as I am using Snow Leopard (10.6.8) and I want to be able to via MPEG-2 transport streams. I paid £14.00 - everything downloaded and installed fine but it doesn't work and I am still unable to

  • Bug: "Read metadata from file"

    When I add GPS coordinates to a file (with the program Geotagger) and select "read metadata from file" to import the new metadata, a color adjustment badge appears on the thumbnail (even though I didn't adjust any colors). This only happens with file

  • BT Vision - Continuous problems, error codes etc

    This is my second home move with BT Broadband/BT Vision and I must say it has been an absolute disaster. For example, I have had error code C03 for 4 weeks now and each time I have been told by the helpline that the account needs to be re-ordered. I

  • Please HELP! Flashed N900 Big mistake :o(

    I flashed my N900 under advice.  Now it shows no sim card present. Tried other sims dont show them either.  I cannot live without my phone...  To all you clever people out there who no something, anything or lots more than this idot typing this, I am