web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache...

26
1 XMLType documents unstructured CLOB storage The default storage model is structured storage. To override this behavior, and store the entire XML document as a single LOB column, use the STORE AS CLOB clause. create table T1 of XMLType XMLTYPE store as CLOB;

Upload: nguyendan

Post on 24-Mar-2018

219 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

1

XMLType documents unstructured CLOB storage

The default storage model is structured storage. To override this behavior, and store the entire XML document as a single LOB column, use the STORE AS CLOB clause.

create table T1 of XMLTypeXMLTYPE store as CLOB;

Page 2: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

2

XML editor EditiX

Page 3: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

3

Page 4: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

4

XML data storage with XMLType as CLOB objects

create table T1 of XMLType XMLTYPE store as CLOB;

insert into T1 values (XMLType('<book number="101"> <author>J. Koks</author> <author>I. Sakne</author> <name>XML foundation </name> <year>2008</year> <content> <chapter number="1">Introduction</chapter> <chapter number="2">XML basics</chapter> <chapter number="3">XML transformastions</chapter> </content></book>'));

insert into T1 values (XMLType('<book number="102"> <author>A. Celms</author> <author>J. Priede</author> <name>Java technology</name> <year>2009</year> <content> <chapter number="1">Introduction</chapter> <chapter number="2">Java basics</chapter> <chapter number="3">Classes and objects</chapter> </content></book>'));

SET long 10000;SET pages 5000;

Page 5: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

5

select Value(a) from T1 a;

Page 6: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

6

Metadata output

select DBMS_METADATA.GET_DDL('TABLE','T1')from DUAL;

CREATE TABLE "SYSTEM"."T1" OF XMLTYPE XMLTYPE STORE AS BASICFILE CLOB ( TABLESPACE "SYSTEM" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10 NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "SYSTEM"

Page 7: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

7

XMLType object data output with EXTRACT() function

select EXTRACT(OBJECT_VALUE, '/book/name') "NAME"from T1;

select EXTRACT(OBJECT_VALUE, '/book/name/text()') "NAME"from T1;

select EXTRACT(OBJECT_VALUE, '/book/author[2]') "AUTHOR"from T1;

Page 8: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

8

select EXTRACT(OBJECT_VALUE, '/child::book/*/*') "CHAPTER"from T1;

select EXTRACT(OBJECT_VALUE, '/child::book/*/text()') "CHAPTER"from T1;

Page 9: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

9

XML data input using XML file

1. Directory of XML files definition:

create or replace directory XMLDIR as 'G:/__XML_tehnologijas1/XML_piemeri';

2. XML file bookshop.xml

<?xml version="1.0" encoding="UTF-8"?><!-- New document created with EditiX at Fri Nov 25 12:25:33 EET 2011 --><bookshop> <book number="101"> <author>J. Koks</author> <author>I. Sakne</author> <name>XML foundation </name> <year>2008</year> <content> <chapter number="1">Introduction</chapter> <chapter number="2">XML basics</chapter> <chapter number="3">XML transformastions</chapter> </content> </book> <book number="102"> <author>A. Celms</author> <author>J. Priede</author> <name>Java technology</name> <year>2009</year> <content> <chapter number="1">Introduction</chapter> <chapter number="2">Java basics</chapter> <chapter number="3">Classes and objects</chapter> </content> </book></bookshop>

Page 10: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

10

3. XMLType table creation:

create table T2 of XMLTypeXMLTYPE store as CLOB;

4. XML data input:

insert into T2 values (xmltype( bfilename('XMLDIR', 'bookshop.xml'), nls_charset_id('AL32UTF8') ) );

5. Data extraction

select EXTRACT(OBJECT_VALUE, '/bookshop/book[2]/author[2]') "BOOK"from T2;

select EXTRACT(OBJECT_VALUE, '//book[@number = 102]/name/text()') "BOOK"from T2;

Page 11: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

11

select Value(a) from T2 a;

Page 12: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

12

XML document schema creation with EditiX editor

Page 13: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

13

<?xml version="1.0" encoding="UTF-8"?><xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="content"><xs:complexType>

<xs:sequence><xs:element ref="chapter" maxOccurs="unbounded"/>

</xs:sequence></xs:complexType>

</xs:element><xs:element name="author" type="xs:string"/><xs:element name="chapter">

<xs:complexType><xs:simpleContent>

<xs:extension base="xs:string"><xs:attribute name="number" type="xs:string"

use="required"/></xs:extension>

</xs:simpleContent></xs:complexType>

</xs:element><xs:element name="bookshop">

<xs:complexType><xs:sequence>

<xs:element ref="book" maxOccurs="unbounded"/></xs:sequence>

</xs:complexType></xs:element><xs:element name="name" type="xs:string"/><xs:element name="book">

<xs:complexType><xs:sequence>

<xs:element ref="author" maxOccurs="unbounded"/><xs:element ref="name"/><xs:element ref="year"/><xs:element ref="content"/>

</xs:sequence><xs:attribute name="number" type="xs:string"

use="required"/></xs:complexType>

</xs:element><xs:element name="year" type="xs:string"/>

</xs:schema>

Page 14: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

14

XML document schema registration

begin

DBMS_XMLSCHEMA.REGISTERSCHEMA(

SCHEMAURL => 'http://localhost:8080/public/bookshop.xsd',

SCHEMADOC => bfilename('XMLDIR', 'bookshop.xsd'),

LOCAL => TRUE,

CSID => nls_charset_id('AL32UTF8') ) ;

end;

Page 15: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

15

CLOB storage with schema

create table T3 of XMLType XMLTYPE STORE as CLOB XMLSCHEMA "http://localhost:8080/public/bookshop.xsd" ELEMENT "bookshop"; insert into T3 values (xmltype(bfilename('XMLDIR', 'bookshop.xml'),nls_charset_id('AL32UTF8') ) );

select EXTRACT(OBJECT_VALUE, '/bookshop/book/author') "author"from T3;

select EXTRACT(OBJECT_VALUE, '/child::bookshop/*/*/text()') "chapter"from T3;

Page 16: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

16

Table with XMLType colon

create table T4(ID varchar2(40),NAME varchar2(20),DATA XMLType);

insert into T4(ID, NAME, DATA) values (sys_guid(), 'Zvaigzne','<bookshop> <book number="101"> <author>J. Koks</author> <author>I. Sakne</author> <name>XML foundation </name> <year>2008</year> <content> <chapter number="1">Introduction</chapter> <chapter number="2">XML basics</chapter> <chapter number="3">XML transformastions</chapter> </content> </book> <book number="102"> <author>A. Celms</author> <author>J. Priede</author> <name>Java technology</name> <year>2009</year> <content> <chapter number="1">Introduction</chapter> <chapter number="2">Java basics</chapter> <chapter number="3">Classes and objects</chapter> </content> </book></bookshop>');

Page 17: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

17

XML data output

set long 10000;set pages 5000;

select a.ID, a.NAME, a.DATA from T4 a;

Page 18: Web viewtablespace "system" enable storage in row chunk 8192 pctversion 10. nocache logging . storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645

18

Meta-data output

select DBMS_METADATA.GET_DDL('TABLE','T4')from DUAL;

CREATE TABLE "SYSTEM"."T4" ( "ID" VARCHAR2(40),

"NAME" VARCHAR2(20), "DATA" "XMLTYPE"

) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "SYSTEM" XMLTYPE COLUMN "DATA" STORE AS BASICFILE CLOB ( TABLESPACE "SYSTEM" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10 NOCACHE LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT))