|
HOWTO: subjects.
HOWTO: XMLType
SYS.XMLType
SYS.XMLType เป็น System-defined type ซึ่ง SYS.XMLType นั้น ช่วยให้เราสามารถจัดเก็บ
และดึงข้อมูลที่เป็นลักษณะ XML ใน Database รวมทั้งมี Functions
ต่างๆ ที่ช่วยให้เราสามารถ access, extract หรือ query ข้อมูลที่เป็น
XML ได้โดยใช้ Xpath expressions ได้สะดวก และมีประสิทธิภาพ
Prerequistires:
Oracle9I Database (9.0.1)
Purpose:
แสดงตัวอย่าง อย่างง่ายในการใช้งาน XMLTypeโดยใช้ SQL Statement
Step-by-Step Example:
SQLเราสามารถใช้สร้าง Table ที่มี Column เป็น XMLType
เราสามารถเรียกใช้งาน createXML() Function ซึ่งเป็น Static Function
ใน XMLType ในการ สร้าง XMLType instancees ของการ Insert ได้ จากนั้นเราสามารถดึงข้อมูลที่จัดเป็นได้โดยใช้
Standard SQL
Creating XMLType
Column
|
SQL> create
table peoples(
2 people_id number(3),
3 people_spec
sys.xmltype);
Table created.
|
Inserting
values into and XMLType Column
|
SQL> insert into peoples
2 values(8,
3 sys.xmltype.createxml('<?xml version="1.0"?>
4 <people>
5 <name>Teddy</name>
6 <loc>UK</loc>
7 <tel>272728 </tel>
8 <email>teddy@exzilla.net</email>
9 </people>
10 ')
11 );
1 row created.
SQL> insert into peoples
2 values(9,
3 sys.xmltype.createxml('<?xml version="1.0"?>
4 <people>
5 <name>Fuju</name>
6 <loc>BKK</loc>
7 <tel>272739</tel>
8 <email>fuju@exzilla.net</email>
9 </people>
10 ')
11 );
1 row created.
SQL> commit;
Commit complete.
SQL>
|
Using XMLType
in a SQL Statement
|
SQL> select
2 p.people_id,
3 p.people_spec.extract('/people/name/text()').getStringVal()
"Name"
4 from peoples
p;
PEOPLE_ID Name
---------- --------------
8 Fuju
9 Teddy
SQL>
|
Updating an XMLType
column
|
SQL> update
peoples set people_spec =
2 sys.XMLType.createxml('<?xml
version="1.0"?>
3 <people>
4 <name>Teera</name>
5 <loc>UK</loc>
6 <tel>272449</tel>
7 <email>teddy@exzilla.net</email>
8 </people>
9 ')
10 where people_id=9;
1 row updated.
SQL>
SQL> select
2 p.people_id,
3 p.people_spec.extract('/people/name/text()').getStringVal()
"Name"
4 from peoples
p;
PEOPLE_ID Name
---------- --------------
8 Fuju
9 Teera
SQL>
|
Deleting a row
containing an XMLType Column
|
SQL> delete
from peoples p
2 where
3 p.people_spec.extract('/people/name/text()').getStringVal()
4 = 'Teera';
1 row deleted.
SQL> select
2 p.people_id,
3 p.people_spec.extract('/people/name/text()').getStringVal()
"Name"
4 from peoples
p;
PEOPLE_ID Name
---------- --------------
8 Fuju
SQL>
|
Note:
XPath is another standard developed by the W3C committee to traverse
XML documents. Oracle XMLType functions support a subset of the
W3C XPath expressions
Extensible Markup Language (XML) is a standard format developed
by the World Wide Web Consortium (W3C) a for representing structured
and unstructured data on the Web.
Universal Resource Identifiers (URIs) identify resources such
as Web pages anywhere on the Web
Complete Sample
code:
Code
listing
References:
Oracle9i Application Developer's Guide - XML Release 1 (9.0.1)
Part Number A88894-01
More Information:
Oracle9i Database README Release Notes Release 9.0.1.0
Oracle9i Application Developer's Guide - XML Release 1 (9.0.1)
Part Number A88894-01
Keywords:
SYS.XMLType XMLType Example
|