2017-08-18 54 views
1

我發現下面的鏈接非常有用的,但我想進一步問它更新XML標籤 - 加入另一個表

Update xml tag in a CLOB column in Oracle

在以前的帖子使用相同的數據:

create table tmp_tab_noemail_test (sce_msg clob); 
insert into tmp_tab_noemail_test values (
'<Energy xmlns="http://euroconsumers.org/notifications/2009/01/notification">  
    <Gender>M</Gender> 
    <FirstName>MAR</FirstName> 
    <Name>VAN HALL</Name> 
    <Email/><Telephone>000000000</Telephone> 
    <InsertDate>2013-10-09</InsertDate> 
</Energy>'); 

update tmp_tab_noemail_test p1 
set p1.sce_msg = updatexml(xmltype(p1.sce_msg), 
    '/Energy/InsertDate/text()','Not Valid', 
    'xmlns="http://euroconsumers.org/notifications/2009/01/notification"').getClobVal(); 

現在,如果我想查找另一個表帳戶,該怎麼辦。它有專欄:acct_num,name,date_of_birth

如何更新InsertDate tag value = Account.date_of_birth where Name tag value = Account.name

可以嗎?謝謝!

回答

0

如果我理解正確的問題,那麼你就可以提取tmp_tab_noemail_testNamerowid,與Account表加入他們的行列,獲得更新的XML和使用merge(由ROWID)在目標文件夾更新 -

create table Account (acct_num varchar2(20), name varchar2(255), date_of_birth date); 

insert into Account 
values(123, 'VAN HALL', sysdate); 
commit; 

merge into tmp_tab_noemail_test t 
using 
(
select rid, updatexml(xmltype(sce_msg), 
     '/Energy/InsertDate/text()', to_char(date_of_birth, 'yyyy-mm-dd'), 
     'xmlns="http://euroconsumers.org/notifications/2009/01/notification"').getClobVal() as sce_msg 
from 
    (select t.sce_msg, t.rid, t.name, a.date_of_birth 
    from 
     (select sce_msg, extractvalue(xmltype(sce_msg), 
       '/Energy/Name', 
       'xmlns="http://euroconsumers.org/notifications/2009/01/notification"') as name, 
       rowid as rid 
     from tmp_tab_noemail_test) t, Account a 
    where t.name = a.name) 
) s 
ON (t.ROWID = s.RID) 
WHEN MATCHED THEN 
UPDATE SET 
    T.sce_msg = S.sce_msg;