2010-10-20 13 views
5

Oracle XML veri türüyle nasıl çalışırsınız?oracle xml veri türünü nasıl kullanacağınız hakkında hızlı tanıtım

Bu soru sadece başkalarıyla bilgi paylaşmak için, bana göre asked and answered olması amaçlanmıştır Aşağıdaki örnek, SQL, XMLType veri türünü içeren sorgulama ve güncelleme veritabanı alanları eklemek için nasıl kullanılacağını gösterir

+1

KÖTÜ İŞ. Ya bir blog olsun ya da bu topluluğu wiki yap! –

+3

Nasıl "topluluk wiki" yaparsınız? [Stackoverflow faq] (http://stackoverflow.com/faq) – corydoras

+0

'a göre, bu tür bir şey yapmanın teşvik edildiği izlenimindeyim. Yine de bir soru olmalı. "Nasıl çalışırım" biraz geniş. Yine de +1. – Thilo

cevap

8

:

-- Create a table that can store XML 
create table sample_xml (id number, xml xmltype); 

-- Insert some XML into the table 
insert into sample_xml values (1, xmltype.createxml('<subject><name>test</name><list><li>a</li><li>b</li></list></subject>')); 
insert into sample_xml values (2, xmltype.createxml('<subject><name>test</name><list><li>a</li></list></subject>')); 

-- When doing a select, refer to table using the alias or getClobVal() will not work 
select t.id, t.xml.getClobVal() from sample_xml t; 

-- Update text of a single xml element 
UPDATE sample_xml SET xml = UPDATEXML(xml, '/subject/name/text()','happy') WHERE id = 2; 

-- Select out just the name for each row in the table using xpath 
select id, extractvalue(xml, '/subject/name/text()') from sample_xml; 

-- Doing an sample_xml, where the xpath string matches two elements, the text of both elements will be updated 
UPDATE sample_xml SET xml = UPDATEXML(xml, '/subject/list/li/text()','one'); 
İlgili konular