Skip to Content
CSC Banner Client-Side Image MapCSC Banner Client-Side Image Map
About us Academics Research Directories News Events Employment Centers Contact Us
Department of Computer Science NC State University College of Engineering

A simple XML Type exercise for Oracle 9i Release 1

As of Oracle 9i release 1, you can use XMLType as a datatype in your tables. XMLType can be used to store and query XML data in the database. As a type, XMLType has member functions to access, extract, and query XML data using a class of operations known as Xpath expressions.

The following listing shows the creation of a table using the XMLType datatype (text in BOLD is SQL code that you must type):

create table MY_XML_TABLE
(Key1 NUMBER,
Xml_column SYS.XMLTYPE);

If you describe the table, you will see its columns:

desc MY_XML_TABLE

Yo can now insert values into MY_XML_TABLE by calling XMLType's CREATEXML method:

insert into MY_XML_TABLE (Key1, Xml_Column)
values (1, SYS.XMLTYPE.CREATEXML
('<book>
<title>MYLEDGER</title>
<chapter num = "1 ">
<title>Beginning</title>
<text>This is the ledger of G.B. Talbot</text>
</chapter>
</book>'));

You can query the data by calling the GETCLOBVAL method. This query

select M.Xml_Column.GETCLOBVAL() as XML_DATA from MY_XML_TABLE M where Key1=1;

returns this data:

<book>
< title>MYLEDGER</title>
< chapter num = "1 ">
< title>Beginning</title>
< text>This is the ledger of G.B. Talbot</text>
</chapter>

For further information on XML please check Oracle9i Database Online Documentation

Department of Computer Science, NC State University - 890 Oval Drive, Campus Box 8206- Raleigh, NC 27695-8206
Copyright © 2004 NC State University. webmaster@csc.ncsu.edu - About this Web site - Site Map
Last Modified on Wed 27 Sep 2006 8:54 AM