2017-08-18 2 views
1

Je trouve le lien suivant très utile, mais je voudrais demander plus à cemise à jour balise xml dans Oracle - se joindre à une autre table

Update xml tag in a CLOB column in Oracle

En utilisant les mêmes données post précédent:

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(); 

Maintenant, que se passe-t-il si je veux rechercher une autre table Compte. Il a la colonne: acct_num, name, date_of_birth

Comment puis-je mettre à jour InsertDate tag value = Account.date_of_birth where Name tag value = Account.name?

Est-il possible de faire? Merci!

Répondre

0

Si je comprends bien la question, alors vous pouvez extraire Name et rowid de tmp_tab_noemail_test, les joindre à Account table, obtenir XML mis à jour et en utilisant merge (par rowid) mise à jour dans le dossier de destination -

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;