Oracle XQuery delete, insert, update











up vote
1
down vote

favorite












Everything below I am able to do in separate operations, but as I am relatively new to XQuery I am struggling to work out how to perform multiple operations in one go which would be neat.



I am trying to update an XML column, with some xml data from another column (this XML has come from a spreadsheet with two columns, promotion numbers and the department numbers within each promotion). Which I load into a table and then run the below against.



INSERT INTO proms
select promid, '<Promotion><MultibuyGroup><MMGroupID>'||depts||'</MMGroupID>
</MultibuyGroup></Promotion>' DEPTS
from (
SELECT promid, listagg (id,'</MMGroupID><MMGroupID>') within GROUP
(ORDER BY id) as depts FROM mmgroups
GROUP BY promid
);


Creating a table with a column for PROMID and an XML Column like the below (just one MMGroup in example for ease of read.



   <Promotion><MultibuyGroup><MMGroupID>1</MMGroupID></Promotion></MultibuyGroup>


When I run the below, I can successfully update any XML in the PROMOTIONS where the value of ID column matches the value of PROMID in the table I have created above.



merge into PROMOTIONS tgt  
using (
select PROMID
, xmlquery('/Promotion/MultibuyGroup/MMGroupID'
passing xmlparse(document DEPTS)
returning content
) as new_mmg
from PROMS WHERE PROMID = 'EMP35Level1'

) src
on (tgt.ID = src.PROMID)

when matched then update
set tgt.xml =
xmlserialize(document
xmlquery(
'copy $d := .
modify
insert node $new_mmg as last into $d/Promotion/MultibuyGroup
return $d'
passing xmlparse(document tgt.xml)
, src.new_mmg as "new_mmg"
returning content
)
no indent
) ;


However what I would like my query to do is to delete any existing MMGroupID nodes from the target xml (if they exist), then replace them with all of the nodes from source xml.



Also within the target xml is a LastUpdated Node which I would like to update with the SYSDATE at time of update



Also two separate columns LAST_UPDATED DATE and ROW_UPDATED NUMBER (20,0) which has the epoch time of update would be nice to update at the same time.



        <Promotion>
<LastUpdated>2018-08-23T14:56:35+01:00</LastUpdated>
<MajorVersion>1</MajorVersion>
<MinorVersion>52</MinorVersion>
<PromotionID>EMP35Level1</PromotionID>
<Description enabled="1">Staff Discount 15%</Description>
<MultibuyGroup>
<AlertThresholdValue>0.0</AlertThresholdValue>
<AlertThresholdValue currency="EUR">0.0</AlertThresholdValue>
<UseFixedValueInBestDeal>0</UseFixedValueInBestDeal>
<UpperThresholdValue>0.0</UpperThresholdValue>
<UpperThresholdValue currency="EUR">0.0</UpperThresholdValue>
<GroupDescription>Employee Discount 15%</GroupDescription>
<Rolling>0</Rolling>
<DisableOnItemDiscount>1</DisableOnItemDiscount>
<UniqueItems>0</UniqueItems>
<AllItems>0</AllItems>
<RoundingRule>3</RoundingRule>
<UseLowestNetValue>0</UseLowestNetValue>
<TriggerOnLostSales>0</TriggerOnLostSales>
<MMGroupID>2</MMGroupID>
<MMGroupID>8</MMGroupID>
<MMGroupID>994</MMGroupID>
</MultibuyGroup>
<Timetable>
<XMLSchemaVersion>1</XMLSchemaVersion>
<CriterionID/>
<StartDate>1970-01-01T00:00:00+00:00</StartDate>
<FinishDate>2069-12-31T00:00:00+00:00</FinishDate>
</Timetable>
<AllowedForEmployeeSale>1</AllowedForEmployeeSale>
<Notes enabled="1"/>
<AlertMessage enabled="1"/>
</Promotion>


Since posting, have edited the query to be:



 merge INTO PROMOTIONS3 tgt
using (
SELECT PROMID
,xmlquery('/Promotion/MultibuyGroup/MMGroupID'
passing xmlparse(document DEPTS)
returning content
) as new_mmg
FROM PROMS WHERE PROMID = 'EMP35Level1'
) src
ON (tgt.ID = src.PROMID)
when matched then update
SET tgt.xml =
xmlserialize(document
xmlquery(
'copy $d := .
modify(
delete nodes $d/Promotion/MultibuyGroup/MMGroupID,
insert node $new_mmg as last into $d/Promotion/MultibuyGroup,
replace value of node $d/Promotion/LastUpdated with current-dateTime())
return $d'
passing xmlparse(document tgt.xml)
,src.new_mmg as "new_mmg"
returning content
)
no indent
)
,last_updated = (SELECT SYSDATE FROM dual)
,row_updated = (SELECT ( SYSDATE - To_date('01-01-1970 00:00:00','DD-MM-YYYY HH24:MI:SS') ) * 24 * 60 * 60 * 1000 FROM dual) ;


So almost correct, except I need



 <LastUpdated>2018-08-23T14:56:35+01:00</LastUpdated>


Not



  <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>


So I need to figure that out.



Cheers.










share|improve this question




























    up vote
    1
    down vote

    favorite












    Everything below I am able to do in separate operations, but as I am relatively new to XQuery I am struggling to work out how to perform multiple operations in one go which would be neat.



    I am trying to update an XML column, with some xml data from another column (this XML has come from a spreadsheet with two columns, promotion numbers and the department numbers within each promotion). Which I load into a table and then run the below against.



    INSERT INTO proms
    select promid, '<Promotion><MultibuyGroup><MMGroupID>'||depts||'</MMGroupID>
    </MultibuyGroup></Promotion>' DEPTS
    from (
    SELECT promid, listagg (id,'</MMGroupID><MMGroupID>') within GROUP
    (ORDER BY id) as depts FROM mmgroups
    GROUP BY promid
    );


    Creating a table with a column for PROMID and an XML Column like the below (just one MMGroup in example for ease of read.



       <Promotion><MultibuyGroup><MMGroupID>1</MMGroupID></Promotion></MultibuyGroup>


    When I run the below, I can successfully update any XML in the PROMOTIONS where the value of ID column matches the value of PROMID in the table I have created above.



    merge into PROMOTIONS tgt  
    using (
    select PROMID
    , xmlquery('/Promotion/MultibuyGroup/MMGroupID'
    passing xmlparse(document DEPTS)
    returning content
    ) as new_mmg
    from PROMS WHERE PROMID = 'EMP35Level1'

    ) src
    on (tgt.ID = src.PROMID)

    when matched then update
    set tgt.xml =
    xmlserialize(document
    xmlquery(
    'copy $d := .
    modify
    insert node $new_mmg as last into $d/Promotion/MultibuyGroup
    return $d'
    passing xmlparse(document tgt.xml)
    , src.new_mmg as "new_mmg"
    returning content
    )
    no indent
    ) ;


    However what I would like my query to do is to delete any existing MMGroupID nodes from the target xml (if they exist), then replace them with all of the nodes from source xml.



    Also within the target xml is a LastUpdated Node which I would like to update with the SYSDATE at time of update



    Also two separate columns LAST_UPDATED DATE and ROW_UPDATED NUMBER (20,0) which has the epoch time of update would be nice to update at the same time.



            <Promotion>
    <LastUpdated>2018-08-23T14:56:35+01:00</LastUpdated>
    <MajorVersion>1</MajorVersion>
    <MinorVersion>52</MinorVersion>
    <PromotionID>EMP35Level1</PromotionID>
    <Description enabled="1">Staff Discount 15%</Description>
    <MultibuyGroup>
    <AlertThresholdValue>0.0</AlertThresholdValue>
    <AlertThresholdValue currency="EUR">0.0</AlertThresholdValue>
    <UseFixedValueInBestDeal>0</UseFixedValueInBestDeal>
    <UpperThresholdValue>0.0</UpperThresholdValue>
    <UpperThresholdValue currency="EUR">0.0</UpperThresholdValue>
    <GroupDescription>Employee Discount 15%</GroupDescription>
    <Rolling>0</Rolling>
    <DisableOnItemDiscount>1</DisableOnItemDiscount>
    <UniqueItems>0</UniqueItems>
    <AllItems>0</AllItems>
    <RoundingRule>3</RoundingRule>
    <UseLowestNetValue>0</UseLowestNetValue>
    <TriggerOnLostSales>0</TriggerOnLostSales>
    <MMGroupID>2</MMGroupID>
    <MMGroupID>8</MMGroupID>
    <MMGroupID>994</MMGroupID>
    </MultibuyGroup>
    <Timetable>
    <XMLSchemaVersion>1</XMLSchemaVersion>
    <CriterionID/>
    <StartDate>1970-01-01T00:00:00+00:00</StartDate>
    <FinishDate>2069-12-31T00:00:00+00:00</FinishDate>
    </Timetable>
    <AllowedForEmployeeSale>1</AllowedForEmployeeSale>
    <Notes enabled="1"/>
    <AlertMessage enabled="1"/>
    </Promotion>


    Since posting, have edited the query to be:



     merge INTO PROMOTIONS3 tgt
    using (
    SELECT PROMID
    ,xmlquery('/Promotion/MultibuyGroup/MMGroupID'
    passing xmlparse(document DEPTS)
    returning content
    ) as new_mmg
    FROM PROMS WHERE PROMID = 'EMP35Level1'
    ) src
    ON (tgt.ID = src.PROMID)
    when matched then update
    SET tgt.xml =
    xmlserialize(document
    xmlquery(
    'copy $d := .
    modify(
    delete nodes $d/Promotion/MultibuyGroup/MMGroupID,
    insert node $new_mmg as last into $d/Promotion/MultibuyGroup,
    replace value of node $d/Promotion/LastUpdated with current-dateTime())
    return $d'
    passing xmlparse(document tgt.xml)
    ,src.new_mmg as "new_mmg"
    returning content
    )
    no indent
    )
    ,last_updated = (SELECT SYSDATE FROM dual)
    ,row_updated = (SELECT ( SYSDATE - To_date('01-01-1970 00:00:00','DD-MM-YYYY HH24:MI:SS') ) * 24 * 60 * 60 * 1000 FROM dual) ;


    So almost correct, except I need



     <LastUpdated>2018-08-23T14:56:35+01:00</LastUpdated>


    Not



      <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>


    So I need to figure that out.



    Cheers.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Everything below I am able to do in separate operations, but as I am relatively new to XQuery I am struggling to work out how to perform multiple operations in one go which would be neat.



      I am trying to update an XML column, with some xml data from another column (this XML has come from a spreadsheet with two columns, promotion numbers and the department numbers within each promotion). Which I load into a table and then run the below against.



      INSERT INTO proms
      select promid, '<Promotion><MultibuyGroup><MMGroupID>'||depts||'</MMGroupID>
      </MultibuyGroup></Promotion>' DEPTS
      from (
      SELECT promid, listagg (id,'</MMGroupID><MMGroupID>') within GROUP
      (ORDER BY id) as depts FROM mmgroups
      GROUP BY promid
      );


      Creating a table with a column for PROMID and an XML Column like the below (just one MMGroup in example for ease of read.



         <Promotion><MultibuyGroup><MMGroupID>1</MMGroupID></Promotion></MultibuyGroup>


      When I run the below, I can successfully update any XML in the PROMOTIONS where the value of ID column matches the value of PROMID in the table I have created above.



      merge into PROMOTIONS tgt  
      using (
      select PROMID
      , xmlquery('/Promotion/MultibuyGroup/MMGroupID'
      passing xmlparse(document DEPTS)
      returning content
      ) as new_mmg
      from PROMS WHERE PROMID = 'EMP35Level1'

      ) src
      on (tgt.ID = src.PROMID)

      when matched then update
      set tgt.xml =
      xmlserialize(document
      xmlquery(
      'copy $d := .
      modify
      insert node $new_mmg as last into $d/Promotion/MultibuyGroup
      return $d'
      passing xmlparse(document tgt.xml)
      , src.new_mmg as "new_mmg"
      returning content
      )
      no indent
      ) ;


      However what I would like my query to do is to delete any existing MMGroupID nodes from the target xml (if they exist), then replace them with all of the nodes from source xml.



      Also within the target xml is a LastUpdated Node which I would like to update with the SYSDATE at time of update



      Also two separate columns LAST_UPDATED DATE and ROW_UPDATED NUMBER (20,0) which has the epoch time of update would be nice to update at the same time.



              <Promotion>
      <LastUpdated>2018-08-23T14:56:35+01:00</LastUpdated>
      <MajorVersion>1</MajorVersion>
      <MinorVersion>52</MinorVersion>
      <PromotionID>EMP35Level1</PromotionID>
      <Description enabled="1">Staff Discount 15%</Description>
      <MultibuyGroup>
      <AlertThresholdValue>0.0</AlertThresholdValue>
      <AlertThresholdValue currency="EUR">0.0</AlertThresholdValue>
      <UseFixedValueInBestDeal>0</UseFixedValueInBestDeal>
      <UpperThresholdValue>0.0</UpperThresholdValue>
      <UpperThresholdValue currency="EUR">0.0</UpperThresholdValue>
      <GroupDescription>Employee Discount 15%</GroupDescription>
      <Rolling>0</Rolling>
      <DisableOnItemDiscount>1</DisableOnItemDiscount>
      <UniqueItems>0</UniqueItems>
      <AllItems>0</AllItems>
      <RoundingRule>3</RoundingRule>
      <UseLowestNetValue>0</UseLowestNetValue>
      <TriggerOnLostSales>0</TriggerOnLostSales>
      <MMGroupID>2</MMGroupID>
      <MMGroupID>8</MMGroupID>
      <MMGroupID>994</MMGroupID>
      </MultibuyGroup>
      <Timetable>
      <XMLSchemaVersion>1</XMLSchemaVersion>
      <CriterionID/>
      <StartDate>1970-01-01T00:00:00+00:00</StartDate>
      <FinishDate>2069-12-31T00:00:00+00:00</FinishDate>
      </Timetable>
      <AllowedForEmployeeSale>1</AllowedForEmployeeSale>
      <Notes enabled="1"/>
      <AlertMessage enabled="1"/>
      </Promotion>


      Since posting, have edited the query to be:



       merge INTO PROMOTIONS3 tgt
      using (
      SELECT PROMID
      ,xmlquery('/Promotion/MultibuyGroup/MMGroupID'
      passing xmlparse(document DEPTS)
      returning content
      ) as new_mmg
      FROM PROMS WHERE PROMID = 'EMP35Level1'
      ) src
      ON (tgt.ID = src.PROMID)
      when matched then update
      SET tgt.xml =
      xmlserialize(document
      xmlquery(
      'copy $d := .
      modify(
      delete nodes $d/Promotion/MultibuyGroup/MMGroupID,
      insert node $new_mmg as last into $d/Promotion/MultibuyGroup,
      replace value of node $d/Promotion/LastUpdated with current-dateTime())
      return $d'
      passing xmlparse(document tgt.xml)
      ,src.new_mmg as "new_mmg"
      returning content
      )
      no indent
      )
      ,last_updated = (SELECT SYSDATE FROM dual)
      ,row_updated = (SELECT ( SYSDATE - To_date('01-01-1970 00:00:00','DD-MM-YYYY HH24:MI:SS') ) * 24 * 60 * 60 * 1000 FROM dual) ;


      So almost correct, except I need



       <LastUpdated>2018-08-23T14:56:35+01:00</LastUpdated>


      Not



        <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>


      So I need to figure that out.



      Cheers.










      share|improve this question















      Everything below I am able to do in separate operations, but as I am relatively new to XQuery I am struggling to work out how to perform multiple operations in one go which would be neat.



      I am trying to update an XML column, with some xml data from another column (this XML has come from a spreadsheet with two columns, promotion numbers and the department numbers within each promotion). Which I load into a table and then run the below against.



      INSERT INTO proms
      select promid, '<Promotion><MultibuyGroup><MMGroupID>'||depts||'</MMGroupID>
      </MultibuyGroup></Promotion>' DEPTS
      from (
      SELECT promid, listagg (id,'</MMGroupID><MMGroupID>') within GROUP
      (ORDER BY id) as depts FROM mmgroups
      GROUP BY promid
      );


      Creating a table with a column for PROMID and an XML Column like the below (just one MMGroup in example for ease of read.



         <Promotion><MultibuyGroup><MMGroupID>1</MMGroupID></Promotion></MultibuyGroup>


      When I run the below, I can successfully update any XML in the PROMOTIONS where the value of ID column matches the value of PROMID in the table I have created above.



      merge into PROMOTIONS tgt  
      using (
      select PROMID
      , xmlquery('/Promotion/MultibuyGroup/MMGroupID'
      passing xmlparse(document DEPTS)
      returning content
      ) as new_mmg
      from PROMS WHERE PROMID = 'EMP35Level1'

      ) src
      on (tgt.ID = src.PROMID)

      when matched then update
      set tgt.xml =
      xmlserialize(document
      xmlquery(
      'copy $d := .
      modify
      insert node $new_mmg as last into $d/Promotion/MultibuyGroup
      return $d'
      passing xmlparse(document tgt.xml)
      , src.new_mmg as "new_mmg"
      returning content
      )
      no indent
      ) ;


      However what I would like my query to do is to delete any existing MMGroupID nodes from the target xml (if they exist), then replace them with all of the nodes from source xml.



      Also within the target xml is a LastUpdated Node which I would like to update with the SYSDATE at time of update



      Also two separate columns LAST_UPDATED DATE and ROW_UPDATED NUMBER (20,0) which has the epoch time of update would be nice to update at the same time.



              <Promotion>
      <LastUpdated>2018-08-23T14:56:35+01:00</LastUpdated>
      <MajorVersion>1</MajorVersion>
      <MinorVersion>52</MinorVersion>
      <PromotionID>EMP35Level1</PromotionID>
      <Description enabled="1">Staff Discount 15%</Description>
      <MultibuyGroup>
      <AlertThresholdValue>0.0</AlertThresholdValue>
      <AlertThresholdValue currency="EUR">0.0</AlertThresholdValue>
      <UseFixedValueInBestDeal>0</UseFixedValueInBestDeal>
      <UpperThresholdValue>0.0</UpperThresholdValue>
      <UpperThresholdValue currency="EUR">0.0</UpperThresholdValue>
      <GroupDescription>Employee Discount 15%</GroupDescription>
      <Rolling>0</Rolling>
      <DisableOnItemDiscount>1</DisableOnItemDiscount>
      <UniqueItems>0</UniqueItems>
      <AllItems>0</AllItems>
      <RoundingRule>3</RoundingRule>
      <UseLowestNetValue>0</UseLowestNetValue>
      <TriggerOnLostSales>0</TriggerOnLostSales>
      <MMGroupID>2</MMGroupID>
      <MMGroupID>8</MMGroupID>
      <MMGroupID>994</MMGroupID>
      </MultibuyGroup>
      <Timetable>
      <XMLSchemaVersion>1</XMLSchemaVersion>
      <CriterionID/>
      <StartDate>1970-01-01T00:00:00+00:00</StartDate>
      <FinishDate>2069-12-31T00:00:00+00:00</FinishDate>
      </Timetable>
      <AllowedForEmployeeSale>1</AllowedForEmployeeSale>
      <Notes enabled="1"/>
      <AlertMessage enabled="1"/>
      </Promotion>


      Since posting, have edited the query to be:



       merge INTO PROMOTIONS3 tgt
      using (
      SELECT PROMID
      ,xmlquery('/Promotion/MultibuyGroup/MMGroupID'
      passing xmlparse(document DEPTS)
      returning content
      ) as new_mmg
      FROM PROMS WHERE PROMID = 'EMP35Level1'
      ) src
      ON (tgt.ID = src.PROMID)
      when matched then update
      SET tgt.xml =
      xmlserialize(document
      xmlquery(
      'copy $d := .
      modify(
      delete nodes $d/Promotion/MultibuyGroup/MMGroupID,
      insert node $new_mmg as last into $d/Promotion/MultibuyGroup,
      replace value of node $d/Promotion/LastUpdated with current-dateTime())
      return $d'
      passing xmlparse(document tgt.xml)
      ,src.new_mmg as "new_mmg"
      returning content
      )
      no indent
      )
      ,last_updated = (SELECT SYSDATE FROM dual)
      ,row_updated = (SELECT ( SYSDATE - To_date('01-01-1970 00:00:00','DD-MM-YYYY HH24:MI:SS') ) * 24 * 60 * 60 * 1000 FROM dual) ;


      So almost correct, except I need



       <LastUpdated>2018-08-23T14:56:35+01:00</LastUpdated>


      Not



        <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>


      So I need to figure that out.



      Cheers.







      oracle xquery






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 12:45

























      asked Nov 8 at 8:40









      user3811820

      357




      357
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          For syntax you should google for XQuery Update Facility.

          An example



          xmlquery(  
          'copy $d := .
          modify(
          delete nodes $d/Promotion/MMGroupID,
          replace value of node $d/Promotion/LastUpdated with current-date(),
          insert node <node1>x</node1> as last into $d/Promotion/MultibuyGroup,
          insert node <node2>x</node2> as last into $d/Promotion/MultibuyGroup)
          return $d
          '





          share|improve this answer





















          • Hi, yes that helped a little, obviously I have been searching online for answer. But thanks for the example. Have the query almost working the way I want. But I need to figure out how to "trim" the current-dateTime function as it is populating <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>
            – user3811820
            Nov 9 at 12:34












          • 1) xs:string(current-date()) automagicly is removing milliseconds.
            – Arkadiusz Łukasiewicz
            Nov 9 at 13:56










          • But that also removes hours:minutes:seconds - 2018-11-09+00:00
            – user3811820
            Nov 9 at 14:48












          • xs:string(current-dateTime()) - correct version
            – Arkadiusz Łukasiewicz
            Nov 9 at 15:03










          • Hi, I did try that - however it returns 2018-11-09T15:08:18.629000+00:00 - when i want > 2018-11-09T15:08:18+00:00
            – user3811820
            Nov 9 at 15:09











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204101%2foracle-xquery-delete-insert-update%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          For syntax you should google for XQuery Update Facility.

          An example



          xmlquery(  
          'copy $d := .
          modify(
          delete nodes $d/Promotion/MMGroupID,
          replace value of node $d/Promotion/LastUpdated with current-date(),
          insert node <node1>x</node1> as last into $d/Promotion/MultibuyGroup,
          insert node <node2>x</node2> as last into $d/Promotion/MultibuyGroup)
          return $d
          '





          share|improve this answer





















          • Hi, yes that helped a little, obviously I have been searching online for answer. But thanks for the example. Have the query almost working the way I want. But I need to figure out how to "trim" the current-dateTime function as it is populating <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>
            – user3811820
            Nov 9 at 12:34












          • 1) xs:string(current-date()) automagicly is removing milliseconds.
            – Arkadiusz Łukasiewicz
            Nov 9 at 13:56










          • But that also removes hours:minutes:seconds - 2018-11-09+00:00
            – user3811820
            Nov 9 at 14:48












          • xs:string(current-dateTime()) - correct version
            – Arkadiusz Łukasiewicz
            Nov 9 at 15:03










          • Hi, I did try that - however it returns 2018-11-09T15:08:18.629000+00:00 - when i want > 2018-11-09T15:08:18+00:00
            – user3811820
            Nov 9 at 15:09















          up vote
          1
          down vote













          For syntax you should google for XQuery Update Facility.

          An example



          xmlquery(  
          'copy $d := .
          modify(
          delete nodes $d/Promotion/MMGroupID,
          replace value of node $d/Promotion/LastUpdated with current-date(),
          insert node <node1>x</node1> as last into $d/Promotion/MultibuyGroup,
          insert node <node2>x</node2> as last into $d/Promotion/MultibuyGroup)
          return $d
          '





          share|improve this answer





















          • Hi, yes that helped a little, obviously I have been searching online for answer. But thanks for the example. Have the query almost working the way I want. But I need to figure out how to "trim" the current-dateTime function as it is populating <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>
            – user3811820
            Nov 9 at 12:34












          • 1) xs:string(current-date()) automagicly is removing milliseconds.
            – Arkadiusz Łukasiewicz
            Nov 9 at 13:56










          • But that also removes hours:minutes:seconds - 2018-11-09+00:00
            – user3811820
            Nov 9 at 14:48












          • xs:string(current-dateTime()) - correct version
            – Arkadiusz Łukasiewicz
            Nov 9 at 15:03










          • Hi, I did try that - however it returns 2018-11-09T15:08:18.629000+00:00 - when i want > 2018-11-09T15:08:18+00:00
            – user3811820
            Nov 9 at 15:09













          up vote
          1
          down vote










          up vote
          1
          down vote









          For syntax you should google for XQuery Update Facility.

          An example



          xmlquery(  
          'copy $d := .
          modify(
          delete nodes $d/Promotion/MMGroupID,
          replace value of node $d/Promotion/LastUpdated with current-date(),
          insert node <node1>x</node1> as last into $d/Promotion/MultibuyGroup,
          insert node <node2>x</node2> as last into $d/Promotion/MultibuyGroup)
          return $d
          '





          share|improve this answer












          For syntax you should google for XQuery Update Facility.

          An example



          xmlquery(  
          'copy $d := .
          modify(
          delete nodes $d/Promotion/MMGroupID,
          replace value of node $d/Promotion/LastUpdated with current-date(),
          insert node <node1>x</node1> as last into $d/Promotion/MultibuyGroup,
          insert node <node2>x</node2> as last into $d/Promotion/MultibuyGroup)
          return $d
          '






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 8 at 9:27









          Arkadiusz Łukasiewicz

          4,7191613




          4,7191613












          • Hi, yes that helped a little, obviously I have been searching online for answer. But thanks for the example. Have the query almost working the way I want. But I need to figure out how to "trim" the current-dateTime function as it is populating <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>
            – user3811820
            Nov 9 at 12:34












          • 1) xs:string(current-date()) automagicly is removing milliseconds.
            – Arkadiusz Łukasiewicz
            Nov 9 at 13:56










          • But that also removes hours:minutes:seconds - 2018-11-09+00:00
            – user3811820
            Nov 9 at 14:48












          • xs:string(current-dateTime()) - correct version
            – Arkadiusz Łukasiewicz
            Nov 9 at 15:03










          • Hi, I did try that - however it returns 2018-11-09T15:08:18.629000+00:00 - when i want > 2018-11-09T15:08:18+00:00
            – user3811820
            Nov 9 at 15:09


















          • Hi, yes that helped a little, obviously I have been searching online for answer. But thanks for the example. Have the query almost working the way I want. But I need to figure out how to "trim" the current-dateTime function as it is populating <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>
            – user3811820
            Nov 9 at 12:34












          • 1) xs:string(current-date()) automagicly is removing milliseconds.
            – Arkadiusz Łukasiewicz
            Nov 9 at 13:56










          • But that also removes hours:minutes:seconds - 2018-11-09+00:00
            – user3811820
            Nov 9 at 14:48












          • xs:string(current-dateTime()) - correct version
            – Arkadiusz Łukasiewicz
            Nov 9 at 15:03










          • Hi, I did try that - however it returns 2018-11-09T15:08:18.629000+00:00 - when i want > 2018-11-09T15:08:18+00:00
            – user3811820
            Nov 9 at 15:09
















          Hi, yes that helped a little, obviously I have been searching online for answer. But thanks for the example. Have the query almost working the way I want. But I need to figure out how to "trim" the current-dateTime function as it is populating <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>
          – user3811820
          Nov 9 at 12:34






          Hi, yes that helped a little, obviously I have been searching online for answer. But thanks for the example. Have the query almost working the way I want. But I need to figure out how to "trim" the current-dateTime function as it is populating <LastUpdated>2018-11-09T11:53:10.591000+00:00</LastUpdated>
          – user3811820
          Nov 9 at 12:34














          1) xs:string(current-date()) automagicly is removing milliseconds.
          – Arkadiusz Łukasiewicz
          Nov 9 at 13:56




          1) xs:string(current-date()) automagicly is removing milliseconds.
          – Arkadiusz Łukasiewicz
          Nov 9 at 13:56












          But that also removes hours:minutes:seconds - 2018-11-09+00:00
          – user3811820
          Nov 9 at 14:48






          But that also removes hours:minutes:seconds - 2018-11-09+00:00
          – user3811820
          Nov 9 at 14:48














          xs:string(current-dateTime()) - correct version
          – Arkadiusz Łukasiewicz
          Nov 9 at 15:03




          xs:string(current-dateTime()) - correct version
          – Arkadiusz Łukasiewicz
          Nov 9 at 15:03












          Hi, I did try that - however it returns 2018-11-09T15:08:18.629000+00:00 - when i want > 2018-11-09T15:08:18+00:00
          – user3811820
          Nov 9 at 15:09




          Hi, I did try that - however it returns 2018-11-09T15:08:18.629000+00:00 - when i want > 2018-11-09T15:08:18+00:00
          – user3811820
          Nov 9 at 15:09


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204101%2foracle-xquery-delete-insert-update%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings