Sunday, October 23, 2005

XML (XMLType) inside PL/SQL Oracle 9/10

The XMLType is an OO XML aware data type. It can be used in columns or in PL/SQL just like VARCHAR2 or DATE. XMLType has member functions that allow access to data using XPath.

A quick example extracting a specific value from an XML varchar2 string:
DECLARE
v VARCHAR2(32000) := 'ABC';
x XMLType;
BEGIN
x := XMLType(v);
DBMS_OUTPUT.put_line(
x.extract('/DATA/LINE[1]').getStringVal()
);
DBMS_OUTPUT.put_line(
x.extract('/DATA/LINE[1]/text()').getStringVal()
);
END;

1 comment:

Anonymous said...

Good to see OO XML type integrated in Oracle, there must be some equivalent of this in upcoming Yukon