XML and ORACLE Rosa Isela López Aguilar Noviembre 2008.

Slides:



Advertisements
Similar presentations
Oracle 10g & 11g for Dev Virtual Columns DML error logging
Advertisements

6.830/6.814 Lecture 5 Database Internals Continued September 17, 2014.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Copyright  Oracle Corporation, All rights reserved. 6 Writing Correlated Subqueries.
18 Copyright © Oracle Corporation, All rights reserved. Advanced Subqueries.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
XML and DB2 By Josephine Cheng, Jane Xu IBM Santa Teresa Laboratory Slides edited from the original slides of Yunyu Song.
Database Programming Sections 4– Review of Joins, Group functions, COUNT, DISTINCT, NVL.
Viewing relational data as XML Using Microsoft SQL Server.
Using SQL Queries to Generate XML- Formatted Data Joline Morrison Mike Morrison Department of Computer Science University of Wisconsin-Eau Claire.
 After completing this lesson, you should be able to do the following: ◦ Interpret the concept of a hierarchical query ◦ Create a tree-structured report.
Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data from more than one table using.
2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.
Lecture 24 XML processing. 2 XQuery Formal Semantics ‘goal is to complement XPath/XQuery spec, by defining meaning of expressions with mathematical rigor.
Sections 3 – Joins & Hierarchical Queries
(with Microsoft SQL Server) Svetlin Nakov Telerik Corporation
Basisdata Pertanian. After completing this lesson, you should be able to do the following:  Write SELECT statements to access data from more than one.
Efficient XSLT Processing in Relational Database System Zhen Hua Liu Anguel Novoselsky Oracle Corporation VLDB 2006.
40183 : Oracle XML DB Performance and Tuning Mark D. Drake Senior Product Manager Session id:
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Nikos dimitrakas – IS4/2i1242/2i4042 spring XML Query Languages Database Systems (4th edition) Chapter 30.5, , Articles & Excerpts.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Cursors These slides are licensed under.
DEFAULT Values and the MERGE Statement. 2 home back first prev next last What Will I Learn? Understand when to specify a DEFAULT value. Construct and.
10 Creating and Managing Tables Objectives At the end of this lesson, you will be able to: Describe the main database objects Create tables Describe.
10-1 Copyright  Oracle Corporation, All rights reserved. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
JDeveloper 10g and Oracle ADF Business Components Getting the Most Out of Your Data Avrom Roy-Faderman Senior Programmer November, 2005.
Nikolay Kostov Telerik Corporation
Copyright© 2005 Oracle Corp.1 SQL/XML Jim Melton USA: Oracle Corp. JTC1 SC32N1632.
Fushen Wang, XinZhou, Carlo Zaniolo Using XML to Build Efficient Transaction- Time Temporal Database Systems on Relational Databases In Time Center, 2005.
XML and databases Chap. 12. Databases Today Data today: Structured - Info in databases – Data organized into chunks, similar entities groups together.
1 Oracle 7Up Workshop – Day One - SQL Expression Filters (10g) What is an expression filter ?  Feature to manage and evaluate conditional expressions.
Manipulating Large Data Sets. Lesson Agenda ◦ Manipulating data using subqueries ◦ Specifying explicit default values in the INSERT and UPDATE statements.
4 Copyright © 2007, Oracle. All rights reserved. Manipulating Large Data Sets.
Database Programming Sections 7 & 8 – Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE, DELETE, integrity constraint,
Copyright © 2004, Oracle. All rights reserved. MANIPULATING LARGE DATA SETS Oracle Lecture 10.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
3 Copyright © 2006, Oracle. All rights reserved. Manipulating Large Data Sets.
INCLUDING CONSTRAINTS lecture5. Outlines  What are Constraints ?  Constraint Guidelines  Defining Constraint  NOT NULL constraint  Unique constraint.
8 Copyright © 2007, Oracle. All rights reserved. Managing Schema Objects.
Database Programming Sections 4 – Joins. Marge Hohly2 Overview  Oracle Proprietary Joins (8i and prior): Cartesian Product Equijoin Non-equijoin Outer.
Database Programming Section 15 – Oracle Proprietary Join Syntax and Review 1.
CSED421 Database Systems Lab Join. Human Resources (HR) schema.
1 © Copyright Trivadis SA TVD-XORA : an Oracle XDB based Web Reporting Framework Marc Lieber | October 2003 |
Database Programming Sections 7–Multi-row sub queries, IN, ANY, ALL, Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE,
An Introduction To SQL Part 2 (Special thanks to Geoff Leese)
DML Part 1 Yogiek Indra Kurniawan. All Files Can Be Downloaded at : Menu : “Perkuliahan”
Database Programming Sections 3 – Oracle Joins. Marge Hohly2 Obtaining Data from Multiple Tables: Using Joins.
6 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using Subqueries.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Collection Operators These slides are.
Database Programming Sections 7– Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE, DELETE, integrity constraint,
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
19 Copyright © Oracle Corporation, All rights reserved. Hierarchical Retrieval.
D Copyright © 2004, Oracle. All rights reserved. Using Oracle XML Developer’s Kit.
7 Copyright © 2004, Oracle. All rights reserved. Hierarchical Retrieval.
11 Copyright © 2004, Oracle. All rights reserved. Managing XML Data in an Oracle 10g Database.
4 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
SQL Introduction. Table of Contents 1. SQL and T-SQL Languages 2. The “SoftUni” Database Schema 3. Introducing the SELECT SQL Statement  SQL Operators.
6 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Joins, Subqueries, CTE and Indices
XML: Extensible Markup Language
Querying XML data with Oracle through the semantic layer
Writing Correlated Subqueries
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Using CASE Value expression
Presentation transcript:

XML and ORACLE Rosa Isela López Aguilar Noviembre 2008

Oracle XML DB Oracle Database supports native XML generation. Oracle provides you with several options for generating or regenerating XML data when stored in: Oracle Database, in general Oracle Database in XMLTypes columns and tables

Creating a Table with an XMLType Column CREATE TABLE Ejemplo1(KEYVALUE varchar2(10) primary key, XMLCOLUMN xmltype); select * from Ejemplo1; Creating a Table of XMLType CREATE TABLE XMLTABLE OF XMLType; select * from XMLTABLE;

INSERT INTO ejemplo1 VALUES(100, XMLType(' Owned ')); select * from ejemplo1; Inserting Values on Ejemplo1

INSERT INTO ejemplo1 VALUES(101, XMLType('<PurchaseOrder xmlns:xsi=" xsi:noNamespaceSchemaLocation=" ADAMS PST SCOTT Julie P. Adams ADAMS R20 Julie P. Adams Redwood Shores, CA Ground The Ruling Class Diabolique 8 1/2 ')); select * from ejemplo1; Inserting Values on Ejemplo1

existsNode() Examples That Find a Node to Match the XPath Expression Given this sample XML document, the following existsNode() operators return true (1). SELECT existsNode(XMLCOLUMN,'/PurchaseOrder/Reference')‏ FROM ejemplo1; SELECT existsNode(XMLCOLUMN,'/PurchaseOrder[Reference="ADAMS PST"]')‏ FROM ejemplo1; SELECT existsNode(XMLCOLUMN, FROM ejemplo1; SELECT existsNode(XMLCOLUMN, '/PurchaseOrder/LineItems/LineItem[Description="8 1/2"]')‏ FROM ejemplo1;

Overview of Generating XML Using Standard SQL/XML Functions You can generate XML data using any of the following standard SQL/XML functions supported by Oracle XML DB: XMLELEMENT and XMLATTRIBUTES SQL Functions XMLFOREST SQL Function XMLCONCAT SQL Function XMLAGG SQL Function XMLPI SQL Function XMLCOMMENT SQL Function XMLROOT SQL Function XMLSERIALIZE SQL Function XMLPARSE SQL Function

SELECT XMLCOLUMN, XMLELEMENT("emp", KEYVALUE) AS "result" FROM ejemplo1 WHERE KEYVALUE > 100; XMLELEMENT XMLElement(): Generating Nested XML SELECT XMLELEMENT("Emp", XMLELEMENT("name", XMLCOLUMN), XMLELEMENT ( "emp", KEYVALUE)) AS "result" FROM ejemplo1 WHERE KEYVALUE > 100 ; XMLElement(): Generating an Element for Each Employee with ID Attribute SELECT XMLELEMENT("Emp", XMLATTRIBUTES(KEYVALUE AS "ID") ) AS "result" FROM ejemplo1 WHERE KEYVALUE > 100;

SELECT extract(XMLCOLUMN,'/emp//enumber') FROM ejemplo1; XML EXTRACT Using existsNode() in the WHERE Clause SELECT count(*) FROM ejemplo1 WHERE existsNode(XMLCOLUMN,'/PurchaseOrder[User="ADAM S"]') = 1; DELETE FROM ejemplo1 WHERE existsNode(XMLCOLUMN,'/PurchaseOrder[User="ADAM S"]') = 1; Using delete in the WHERE Clause

XMLELEMENT: Generating an Element for Each Employee This example produces an Emp element for each employee, with the employee name as its content: SELECT e.employee_id, XMLELEMENT ("Emp", e.first_name ||' '|| e.last_name) AS "RESULT" FROM hr.employees e WHERE employee_id > 200; This query produces the following typical result: EMPLOYEE_ID RESULT Michael Hartstein 202 Pat Fay 203 Susan Mavris 204 Hermann Baer 205 Shelley Higgins 206 William Gietz

SELECT KEYVALUE, XMLELEMENT("NUEVO", KEYVALUE||' '||XMLCOLUMN) AS "RESULT" FROM ejemplo2 WHERE KEYVALUE=101; XMLELEMENT: Generating an Element for a Particular Case

XMLELEMENT: Generating Nested XML To produce an Emp element for each employee, with elements that provide the employee name and hire date, do the following: SELECT XMLElement("Emp", XMLElement("name", e.first_name ||' '|| e.last_name), XMLElement("hiredate", e.hire_date)) AS "RESULT" FROM hr.employees e WHERE employee_id > 200 ; RESULT Michael Hartstein Pat Fay Susan Mavris Hermann Baer

XMLELEMENT: Generating Employee Elements with ID and Name Attributes This example produces an Emp element for each employee, with an id and name attribute: SELECT XMLElement("Emp", XMLAttributes( e.employee_id as "ID", e.first_name ||' ' || e.last_name AS "name"))‏ AS "RESULT" FROM hr.employees e WHERE employee_id > 200; RESULT

XMLELEMENT: Generating an Element from a User-Defined Datatype Instance CREATE OR REPLACE TYPE emp_t AS OBJECT NUMBER(4), ENAME VARCHAR2(10)); CREATE OR REPLACE TYPE emplist_t AS TABLE OF emp_t; CREATE OR REPLACE TYPE dept_t AS OBJECT NUMBER(2), DNAME VARCHAR2(14), EMP_LIST emplist_t); SELECT XMLElement("Department", dept_t(department_id, department_name, CAST(MULTISET(SELECT employee_id, last_name FROM hr.employees e WHERE e.department_id = d.department_id)‏ AS emplist_t)))‏ AS deptxml FROM hr.departments d WHERE d.department_id = 10;

This produces an XML document which contains the Department element and the canonical mapping of type dept_t. DEPTXML ACCOUNTING CLARK KING MILLER

Accessing a Text Node Value Matching an XPath Expression Using extractValue()‏ SELECT extractValue(XMLCOLUMN,'/PurchaseOrder/Reference') FROM ejemplo1; SELECT extractValue(XMLCOLUMN,'/Description')‏ FROM ejemplo1, TABLE ( xmlsequence (extract(XMLCOLUMN,'/PurchaseOrder/LineItems/LineItem/Descripti on')‏ )‏ ) t;

Using updateXML() to Replace Contents of a Node Tree Associated with XPath Elements In this example updateXML() replaces the contents of the node tree associated with the element identified by the XPath expression `/PurchaseOrders/LineItems/LineItem[2]'. UPDATE ejemplo1 SET xmlcolumn = updateXML(xmlcolumn, '/PurchaseOrder/LineItems/LineItem[2]', xmltype(' Andrei Rublev <Part Id=" " UnitPrice="39.95" Quantity="2"/> ' )‏ ) WHERE existsNode(XMLCOLUMN, '/PurchaseOrder[Reference="MILLER PST"]' ) = 1; SELECT * FROM ejemplo1;

Using updateXML() to Update a Text Node Value Identified by an XPath Expression This example uses updateXML() to update the value of the text node identified by the XPath expression `/PurchaseOrder/Reference': UPDATE ejemplo1 SET XMLCOLUMN = updateXML(XMLCOLUMN,'/PurchaseOrder/Reference/text()', 'MILLER PST')‏ WHERE existsNode(XMLCOLUMN,'/PurchaseOrder[Reference="ADAMS PST"]') = 1; SELECT * FROM ejemplo1;

XMLFOREST: Generating Elements with Attribute and Child Elements This example generates an Emp element for each employee, with a name attribute and elements with the employee hire date and department as the content. SELECT XMLElement("Emp", XMLAttributes(e.first_name ||' '|| e.last_name AS "name"), XMLForest(e.hire_date, e.department AS "department"))‏ AS "RESULT" FROM employees e WHERE e.department_id = 20; RESULT

XMLFOREST: Generating an Element from a User-Defined Datatype Instance SELECT XMLForest( dept_t(department_id, department_name, CAST (MULTISET (SELECT employee_id, last_name FROM hr.employees e WHERE e.department_id = d.department_id)‏ AS emplist_t))‏ AS "Department")‏ AS deptxml FROM hr.departments d WHERE department_id=10; DEPTXML Administration Whalen

SELECT XMLELEMENT("Emp", XMLFOREST(KEYVALUE, XMLCOLUMN))‏ "Emp Element" FROM ejemplo1 WHERE KEYVALUE > 99; XMLFOREST

CREATE TABLE datosxml(Colxml XMLType); CREATE TABLE xsl_tab (col1 XMLTYPE); Insert Into datosxml Values ( xmltype(' Juan garcia ')); SELECT * FROM datosxml; XMLTRANSFORM

Inserting StyleSheet: INSERT INTO xsl_tab VALUES (XMLTYPE.createxml(' <xsl:stylesheet version="1.0" xmlns:xsl=" > <xsl:sort select="name(.)" data-type="text" order="ascending"/> ')); XMLTRANSFORM

SELECT XMLTRANSFORM(d.colxml, x.col1) FROM datosxml d, xsl_tab x; Result XMLTRANSFORM

ons204.htm 20/xdb03usg.htm#1656 Referencias