Top Banner
XML in Oracle 12c Wolfgang Nast
39

XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

May 26, 2018

Download

Documents

duongtu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

XML in Oracle 12c

Wolfgang Nast

Page 2: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

||

Agenda

XML in Oracle 12c2

• Vorstellung der Möglichkeiten

Klassisch

XDB

• Beispiel XML Schema

• Umsetzung klassisch

• Umsetzung XDB

• Zusammenfassung

Page 3: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Im Überblick

Technologie-orientiert

Branchen-unabhängig

Hauptsitz

Ratingen240

Beschäftigte

Gründungsjahr

1994

Niederlassungen

Frankfurt am Main, Köln

Ausbildungs-

betrieb

Inhabergeführte

Aktiengesellschaft

Zertifizierter

Partner von

Oracle,

Microsoft

und SAP

Page 4: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

||

Vorstellen der Technologien

XML in Oracle 12c4

Page 5: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

||

Klassische XML Abbildung

XML in Oracle 12c5

• Abbildung mit BLOB

• Abbildung mit CLOB

• Abbildung mit Tabellen

Page 6: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

||

XDB Verwendung

XML in Oracle 12c6

• XML Schema in XDB

• Direkte Speicherung als XMLType

• Relationale Views auf XMLType

• XMLType Views auf relationale Daten

Page 7: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

||

XML Schema

XML in Oracle 12c7

• Vorstellung des Beispiel-Schemas

• Anpassen des Schemas für XDB

Page 8: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Beispiel: XML Schema

Teile des Schemas:

- Kapitel

- Autor

- Buch

XML in Oracle 12c8

XML Schema Buch

Page 9: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Kapitel

XML in Oracle 12c9

XML Schema

Page 10: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Kapitel

XML in Oracle 12c10

XML Schema

Page 11: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Autor

XML in Oracle 12c11

XML Schema

Page 12: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Buch

XML in Oracle 12c12

XML Schema

Page 13: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

||

Klassische Abbildung von XML

XML in Oracle 12c13

• Inhalt des Buches als BLOB

• Inhalt des Kapitels als CLOB

• Inhalt des Autors als Tabelle

Page 14: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Tabelle für Buch mit BLOB

Erstellen der Tabelle BUCH_BLOB:

create table buch_blob (id integer generated always as

identity primary key, titel varchar2(100), daten blob);

XML in Oracle 12c14

Klassisch

Page 15: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Tabelle für Buch mit Autoren und Kapiteln

XML in Oracle 12c15

Klassisches Diagramm

Page 16: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Tabelle für Kapitel mit CLOB

Erstellen der Tabelle KAPITEL_CLOB:

create table kapitel_clob (id integer generated always as

identity primary key, überschrift varchar2(100), text clob);

XML in Oracle 12c16

Klassischer Teil

Page 17: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Tabellen für Autor und Buch

Erstellen der Tabelle AUTOR_TAB:

create table autor_tab (id integer generated always as

identity primary key, name varchar2(100), vorname

varchar2(100));

Erstellen der Tabelle BUCH_TAB:

create table buch_tab (id integer generated always as

identity primary key, überschrift varchar2(100));

XML in Oracle 12c17

Klassischer Teil

Page 18: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Beziehungstabellen für Autor, Kapitel und Buch

Erstellen der Tabelle AUTOR_BUCH_REL:

create table autor_buch_rel (buch integer, autor integer,

CONSTRAINT "AUTOR_BUCH_REL_PK" PRIMARY KEY ("BUCH",

"AUTOR"), … FK_AUTOR, … FK_BUCH);

Erstellen der Tabelle KAPITEL_BUCH_REL:

create table kapitel_Buch_rel (buch integer, kapitel

integer, nummer integer, CONSTRAINT "KAPITEL_BUCH_REL_PK"

PRIMARY KEY ("BUCH", "KAPITEL"), … FK_KAPITEL, … FK_BUCH,

CONSTRAINT "BUCH_NR_UK1" UNIQUE ("BUCH", "NUMMER"));

XML in Oracle 12c18

Klassischer Teil

Page 19: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

||

Schema in XDB

XML in Oracle 12c19

• Schema anpassen

• Schema registrieren

• Ergebnis ansehen

Page 20: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Schema anpassen für XDB

Buch Schema normal:

<xsd:import schemaLocation="Autor.xsd"

namespace="http://www.nast.org/xml/Autor"/>

<xsd:import schemaLocation="Kapitel.xsd"

namespace="http://www.nast.org/xml/Kapitel"/>

Buch Schema angepasst:

<xsd:import schemaLocation="http://www.nast.org/xml/Autor"

namespace="http://www.nast.org/xml/Autor"/>

<xsd:import schemaLocation="http://www.nast.org/xml/Kapitel"

namespace="http://www.nast.org/xml/Kapitel"/>

XML in Oracle 12c20

XML Schema

Page 21: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Schema registrieren Abhängigkeiten

Reihenfolge:

- Kapitel (Eigenständig)

- Autor (Eigenständig)

- Buch (Abhängig von Autor und Buch)

XML in Oracle 12c21

XML Schema

Page 22: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Schema registrieren Befehl

SQL/XML Kommando (keine Typen, nur Tabellen):

BEGIN

DBMS_XMLSCHEMA.registerSchema(

'http://www.nast.org/xml/Autor',

'<?xml version="1.0" … </Autor>‚

TRUE, FALSE, FALSE, TRUE, FALSE,

null,

nls_charset_id('AL32UTF8'));

END;

XML in Oracle 12c22

XML Schema

Page 23: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Registrierte Schema

Schema mit Oracle Erweiterungen:…

<xsd:element name="Autor" oraxdb:propNumber="4268"

oraxdb:global="true" oraxdb:SQLType="CLOB"

oraxdb:SQLName="Autor" oraxdb:memType="258"

oraxdb:defaultTable="Autor761_TAB"

oraxdb:defaultTableSchema="WNAST">

<xsd:complexType>

<xsd:attribute name="Name" use="required"

type="xsd:string" oraxdb:propNumber="4266"

oraxdb:global="false" oraxdb:memType="1"/>

XML in Oracle 12c23

XML Schema

Page 24: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Registrierte Schema erzeugte Tabellen

XML in Oracle 12c24

XML Schema

Page 25: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

||

XDB Verwendung

XML in Oracle 12c25

• Direkte Speicherung als XMLType

• Relationale Views auf XMLType

• XMLType Views auf relationale Daten

Page 26: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Direkte Speicherung als XMLType

Anlegen von BUCH_XML:

create table buch_xml of xmltype xmlschema

"http://www.nast.org/xml/Buch" element "Buch";

XML in Oracle 12c26

XDB

Page 27: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

XMLTable

vereinfachte Funktion XMLTable:

XMLTable(XMLNAMESPACES ('namespace' as prefix),

'XPath' passing xmlType_Wert columns Spaltenname Spaltentyp

path 'XPath' default 'Text wenn fehlt',…

Spalten)Tabellenname

XML in Oracle 12c27

XDB XML nach relationale Daten

Page 28: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Relationale View von XMLType

Anlegen von BUCH_REL_VIEW(Ausgabe Spalten):

create view buch_rel_view as select bu.Buchname,

bu.beschreibung, kap.nummer, kap.ueberschrift,

xmlserialize(content kap.text as varchar2(1000)) as "Text"

from buch_xml b,

XML in Oracle 12c28

XDB anlegen, Teil 1

Page 29: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Relationale View von XMLType

Tabellen Teil des Buch XML Element:

xmlTable(XMLNAMESPACES (default

'http://www.nast.org/xml/Buch',

'http://www.nast.org/xml/Kapitel' as k),

'/Buch' passing b.object_value columns Buchname

varchar2(100) path '@Titel',

beschreibung varchar2(1000) path '@Beschreibung' default

'ohne Beschreibung', kapitel xmltype path 'K:Kapitel')bu,

XML in Oracle 12c29

XDB anlegen, Teil 2

Page 30: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Relationale View von XMLType

Tabellen Teil des Kapitel XML Element:

xmltable(XMLNAMESPACES (default

'http://www.nast.org/xml/Kapitel'), '/Kapitel' passing

bu.kapitel columns nummer for ordinality, ueberschrift

varchar2(100) path '@Überschrift', text xmltype path

'child::text()')kap;

XML in Oracle 12c30

XDB anlegen, Teil 3

Page 31: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Relationale View von XMLType

XML in Oracle 12c31

XDB Ergebnis

Page 32: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

XMLElement und XMLAttributes

vereinfachte Funktion XMLElement:

XMLElement("ElementName", xmlattributes(), [Unterelemente])

vereinfachte Funktion XMLAttributes:

XMLAttributes('Wert' as "AttributName", … weitere

Attribute)

XML in Oracle 12c32

XDB relationale Daten nach XML

Page 33: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

XMLForest und XMLAgg

vereinfachte Funktion XMLForest:

XMLForest(Spalte as "ElementName", …weitere Spalten)

vereinfachte Funktion XMLAgg:

XMLAgg(xmlelement(…) order by Spalte)

XML in Oracle 12c33

XDB relationale Daten nach XML

Page 34: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

XMLType Views auf relationale Daten

Anlegen von BUCH_XML_VIEW:

create view buch_xml_view as select xmlroot(

xmlelement("Buch",

xmlattributes('http://www.nast.org/xml/Buch' as "xmlns",

b."ÜBERSCHRIFT" as "Titel"),

xmlagg( xmlelement(NOENTITYESCAPING "Kapitel",

xmlattributes('http://www.nast.org/xml/Kapitel' as "xmlns",

k."ÜBERSCHRIFT" as "Überschrift"), k.TEXT) order by

n.nummer)), VERSION '1.0') as XMLDaten

XML in Oracle 12c34

XDB anlegen, Teil 1

Page 35: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

XMLType Views auf relationale Daten

Anlegen von BUCH_XML_VIEW:

from buch_tab b, kapitel_buch_rel n, kapitel_clob k where

b.id = n.buch and k.id = n.kapitel group by

b."ÜBERSCHRIFT";

XML in Oracle 12c35

XDB anlegen, Teil 2

Page 36: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

XMLType Views auf relationale Daten

XML in Oracle 12c36

XDB Ergebnis

Page 37: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

||

Zusammenfassung

XML in Oracle 12c37

• Direkte Speicherung

• XML erzeugen aus Tabellen

• Teile aus XML extrahieren

• Beispiele als ZIP auf der DOAG Seite

Page 38: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

|

Weitere Vorträge am 16.11.

Page 39: XML in Oracle 12c Abbildung von XML 13 XML in Oracle 12c • Inhalt des Buches als BLOB • Inhalt des Kapitels als CLOB • Inhalt des Autors als Tabelle | Tabelle für Buch mit BLOB

Wolfgang Nast

Telefon: +49 2102 30961 – 0

[email protected]

ROADSHOW

„VON FORMS NACH APEX“

24.01.2017 Hamburg

25.01.2017 Düsseldorf

26.01.2017 Frankfurt

27.01.2017 München