Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quick introduction on how to use oracle xml data type

Tags:

sql

xml

oracle

How do you work with the oracle XML data type?

This question is intended to be asked and answered by me, just to share the information with others

like image 724
corydoras Avatar asked Oct 20 '10 05:10

corydoras


People also ask

What is XML data type in Oracle?

XMLType is a system-defined opaque type for handling XML data. It as predefined member functions on it to extract XML nodes and fragments. You can create columns of XMLType and insert XML documents into it.

What is the use of XML file in Oracle?

Oracle XML DB is the name for a set of Oracle Database technologies related to high-performance XML storage and retrieval. It provides native XML support by encompassing both SQL and XML data models in an interoperable manner.

What is XML data type?

The xml data type is a built-in data type in SQL Server and is somewhat similar to other built-in types such as int and varchar. As with other built-in types, you can use the xml data type as a column type when you create a table as a variable type, a parameter type, a function-return type, or in CAST and CONVERT.

What is Oracle data type explain in detail?

Oracle Built-In Datatypes. A datatype associates a fixed set of properties with the values that can be used in a column of a table or in an argument of a procedure or function.


1 Answers

The following sample SQL demonstrates how to insert, query and update database fields that contain the XMLTYPE data type:

-- 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');
like image 114
2 revs Avatar answered Sep 23 '22 04:09

2 revs