C10. SQL-S + XML Date Semistructurate, 2012-2013.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Advanced SQL (part 1) CS263 Lecture 7.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
XML: Extensible Markup Language
An Introduction to XML Based on the W3C XML Recommendations.
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
Introduction to Structured Query Language (SQL)
29-Jun-15 JAXB Java Architecture for XML Binding.
Database Systems More SQL Database Design -- More SQL1.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
Introduction to Structured Query Language (SQL)
Microsoft Access 2010 Chapter 7 Using SQL.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Viewing relational data as XML Using Microsoft SQL Server.
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
Integrating XML with Microsoft SQL Server ©NIITeXtensible Markup Language/Lesson 9/Slide 1 of 31 Objectives In this lesson, you will learn to: * Generate.
Lecture 15 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
XML in SQL Server Overview XML is a key part of any modern data environment It can be used to transmit data in a platform, application neutral form.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
XP 1 DECLARING A DTD A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
5/24/01 Leveraging SQL Server 2000 in ColdFusion Applications December 9, 2003 Chris Lomvardias SRA International
New Perspectives on XML, 2nd Edition
Database Systems Part VII: XML Querying Software School of Hunan University
Module 18 Querying XML Data in SQL Server® 2008 R2.
An OO schema language for XML SOX W3C Note 30 July 1999.
XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.
Retrieving XML Data from SQL server.  Using the FOR XML Clause to Retrieve Data Retrieving Data in XML Format How SQL Server Generates XML Using the.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
XML and Database.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content.
Working with Columns, Characters, and Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Apply the concatenation.
Chapter 14 1 Chapter 14 Storing and Retrieving XML in SQL Server 2000 November 6, 2001 Sook-Kyo Kwon.
Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 5 courtesy of Ghislain Fourny/ETH © Department of Computer.
SQLXML XML Technology For SQL Server Brian Moore Developer and Platform Strategy Group Microsoft Corporation.
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
XML: Extensible Markup Language
All about JSON Scenarios and value proposition for JSON data enabled in Azure SQL Database and SQL Server Ralph Kemperdick Digital Business Architect,
More SQL: Complex Queries,
Using XML in SQL Server and Azure SQL Database
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Basic select statement
Instructor: Craig Duckett Lecture 09: Tuesday, April 25th, 2017
02 | Advanced SELECT Statements
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
SQL LANGUAGE and Relational Data Model TUTORIAL
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Contents Preface I Introduction Lesson Objectives I-2
IST 318 Database Administration
New Perspectives on XML
Presentation transcript:

C10. SQL-S + XML Date Semistructurate,

C10. DS SQL-S + XML

FOR Clause [ FOR { BROWSE | } ] ::= XML { { RAW [ ( 'ElementName' ) ] | AUTO } [ [, { XMLDATA | XMLSCHEMA [ ( ‘NS_URI‘ ) ] } ] [, ELEMENTS [ XSINIL ] ] | EXPLICIT [ [, XMLDATA ] ] | PATH [ ( 'ElementName' ) ] [ [, ELEMENTS [ XSINIL ] ] ] } ::= [, TYPE ] [, ROOT [ ( 'RootName' ) ] ] C10 - DS

BD Exemple: sectii (cods, denumires) discipline (codd, denumired, detalii) planinv (cods, codd) studenti (cods, nrmatricol, nume, grupa, datan, medie) rezultate (nrmatricol, disciplina, nota) Obs: Discipline.detalii este de tip XML, cu element radacina, si in exemplele prezentate, contine elemente ; exemplu: prof de inele prof de corpuri C10 - DS

XML - Specifies that the results of a query are to be returned as an XML document. One of the following XML modes must be specified: RAW, AUTO, EXPLICIT. RAW [ ('ElementName') ] - Takes the query result and transforms each row in the result set into an XML element with a generic identifier as the element tag. You can optionally specify a name for the row element. The resulting XML output uses the specified ElementName as the row element generated for each row. AUTO - Returns query results in a simple, nested XML tree. Each table in the FROM clause, for which at least one column is listed in the SELECT clause, is represented as an XML element. The columns listed in the SELECT clause are mapped to the appropriate element attributes. EXPLICIT - Specifies that the shape of the resulting XML tree is defined explicitly. Using this mode, queries must be written in a particular way so that additional information about the desired nesting is specified explicitly. C10 - DS

XMLDATA - Returns inline XDR schema, but does not add the root element to the result. If XMLDATA is specified, XDR schema is appended to the document. XMLSCHEMA [ ('TargetNameSpaceURI') ] - Returns inline XSD schema. You can optionally specify a target namespace URI when you specify this directive, which returns the specified namespace in the schema. ELEMENTS - Specifies that the columns are returned as subelements. Otherwise, they are mapped to XML attributes. This option is supported in RAW, AUTO and PATH modes only. You can optionally specify XSINIL or ABSENT when you use this directive. XSINIL specifies that an element that has an xsi:nil attribute set to True be created for NULL column values. By default or when ABSENT is specified together with ELEMENTS, no elements are created for NULL values. XSINIL - Specifies that an element with xsi:nil attribute set to True be created for NULL column values. This option can only be specified with ELEMENTS directive. C10 - DS

PATH [ ('ElementName') ] - Generates a element wrapper for each row in the result set. You can optionally specify an element name for the element wrapper. If an empty string is provided, such as FOR XML PATH ('') ), a wrapper element is not generated. Using PATH may provide a simpler alternative to queries written using the EXPLICIT directive. You can use FOR XML EXPLICIT mode queries to construct this kind of XML from a rowset, but the PATH mode provides a simpler alternative to the possibly cumbersome EXPLICIT mode queries. PATH mode, together with the ability to write nested FOR XML queries and the TYPE directive to return xml type instances, allows you to write queries with less complexity. It provides an alternative to writing most EXPLICIT mode queries. By default, PATH mode generates a element wrapper for each row in the result set. You can optionally specify an element name. If you do, the specified name is used as the wrapper element name. If you provide an empty string (FOR XML PATH ('')), no wrapper element is generated. C10 - DS

TYPE Specifies that the query returns results as xml type. ROOT [ ('RootName') ] Specifies that a single top-level element be added to the resulting XML. You can optionally specify the root element name to generate. If the optional root name is not specified, the default element is added. C10 - DS

Using RAW Mode –RAW mode transforms each row in the query result set into an XML element that has the generic identifier, or the optionally provided element name. –By default, each column value in the rowset that is not NULL is mapped to an attribute of the element. –If the ELEMENTS directive is added to the FOR XML clause, each column value is mapped to a subelement of the element. Together with the ELEMENTS directive, you can optionally specify the XSINIL option to map NULL column values in the result set to an element that has the attribute, xsi:nil="true". C10 - DS

Exemple RAW select * from studenti for xml raw => (...) C10 - DS

Exemple RAW select * from studenti for xml raw, elements => C10 - DS Lupu Teodor Grigore T00:00: Hodis George-Raul Farcas Vasile-Sebastian (...)

Exemple RAW select * from studenti for xml raw, elements xsinil => C10 - DS Lupu Teodor Grigore T00:00: Hodis George-Raul Farcas Vasile-Sebastian (...)

Exemple RAW select * from studenti for xml raw('student') => C10 - DS (...)

Exemple RAW select * from studenti for xml raw('student'), elements => C10 - DS Lupu Teodor Grigore T00:00: Hodis George-Raul Farcas Vasile-Sebastian (...)

Exemple RAW select * from studenti for xml raw('student'), root('facultate') => C10 - DS <student CodS="4" NrMatricol="110" Nume="Lupu Teodor Grigore" Grupa="132" DataN=" T00:00:00" /> <student CodS="6" NrMatricol="152" Nume="Hodis George-Raul" Grupa="821" /> <student CodS="4" NrMatricol="154" Nume="Farcas Vasile-Sebastian" Grupa="342" Medie="7.00" /> (...)

Exemple RAW select CodD, DenumireD, DetaliiDisc = detalii from discipline for xml raw => C10 - DS prof de algebra 1 prof de algebra 2 prof de inele prof de corpuri (…)

Exemple RAW select CodD, DenumireD, DetaliiDisc = detalii from discipline for xml raw, elements => C10 - DS MA001 Structuri algebrice de baza prof de curs structuri prof de seminar structuri MA002 Algebra liniara (…)

Exemple RAW select se.CodS, se.DenumireS, st.NrMatricol, st.Nume from sectii as se inner join studenti as st on st.CodS = se.CodS order by se.cods for xml raw => C10 - DS (...) (...)

Exemple RAW select se.CodS, se.DenumireS, studenti = (select st.NrMatricol, st.Nume from studenti as st where st.CodS = se.CodS for xml raw ('student')) from sectii as se order by se.cods for xml raw, elements => C10 - DS 1 Matematica <student NrMatricol="7587" Nume="Huluban Ovidiu"/><student NrMatricol="8043" Nume="Pop Daniela Ioana"/><student NrMatricol="8070" Nume="Ulici Amalia Laura"/><student NrMatricol="8074" Nume="Vilceanu Veronica Aureli"/> (...) (...)

Exemple RAW select se.CodS, se.DenumireS, studenti = (select st.NrMatricol, st.Nume from studenti as st where st.CodS = se.CodS for xml raw ('student'), type) from sectii as se order by se.cods for xml raw, elements => C10 - DS 1 Matematica (...) (...)

Using AUTO Mode –AUTO mode returns query results as nested XML elements. This does not provide much control over the shape of the XML generated from a query result. The AUTO mode queries are useful if you want to generate simple hierarchies. –Each table in the FROM clause, from which at least one column is listed in the SELECT clause, is represented as an XML element. The columns listed in the SELECT clause are mapped to attributes or subelements, if the optional ELEMENTS option is specified in the FOR XML clause. C10 - DS

Using AUTO Mode –The XML hierarchy, nesting of the elements, in the resulting XML is based on the order of tables identified by the columns specified in the SELECT clause. Therefore, the order in which column names are specified in the SELECT clause is significant. The first, leftmost table that is identified forms the top element in the resulting XML document. The second leftmost table, identified by columns in the SELECT statement, forms a subelement within the top element, and so on. –If a column name listed in the SELECT clause is from a table that is already identified by a previously specified column in the SELECT clause, the column is added as an attribute of the element already created, instead of opening a new level of hierarchy. If the ELEMENTS option is specified, the column is added as an element. C10 - DS

Using AUTO Mode –When a column in the SELECT clause cannot be associated with any of the tables identified in the FROM clause, as in the case of an aggregate column or computed column, the column is added in the XML document in the deepest nesting level in place when it is encountered in the list. If such a column appears as the first column in the SELECT clause, the column is added to the top element. C10 - DS

Exemple AUTO select * from studenti for xml auto => C10 - DS (...)

Exemple AUTO select * from studenti for xml auto, root('facultate'), elements xsinil => C10 - DS Lupu Teodor Grigore T00:00: Hodis George-Raul Farcas Vasile-Sebastian (...)

Exemple AUTO select se.CodS, se.DenumireS, st.NrMatricol, st.Nume from sectii as se inner join studenti as st on st.CodS = se.CodS for xml auto => C10 - DS (...)

Exemple AUTO select se.CodS, se.DenumireS, st.NrMatricol, st.Nume from sectii as se inner join studenti as st on st.CodS = se.CodS order by se.CodS for xml auto => C10 - DS (...) (...)

Exemple AUTO select se.CodS, se.DenumireS, st.NrMatricol, st.Nume, r.disciplina, r.nota from sectii as se inner join studenti as st on st.CodS = se.CodS inner join rezultate as r on r.NrMatricol = st.NrMatricol order by se.cods, st.nrmatricol for xml auto, root('facultate') => C10 - DS

Exemple AUTO (rezultatul exemplului anterior) (...) (...) C10 - DS

Exemple AUTO select se.CodS, se.DenumireS, media = avg(r.nota), st.NrMatricol, st.Nume from sectii as se inner join studenti as st on st.CodS = se.CodS inner join rezultate as r on r.NrMatricol = st.NrMatricol group by se.CodS, se.DenumireS, st.NrMatricol, st.Nume order by se.cods, st.nrmatricol for xml auto, root('facultate') => C10 - DS (...)

Exemple AUTO select se.CodS, se.DenumireS, st.NrMatricol, st.Nume, media = avg(r.nota) from sectii as se inner join studenti as st on st.CodS = se.CodS inner join rezultate as r on r.NrMatricol = st.NrMatricol group by se.CodS, se.DenumireS, st.NrMatricol, st.Nume order by se.cods, st.nrmatricol for xml auto, root('facultate') => C10 - DS

Exemple AUTO (rezultatul exemplului anterior) (...) (...) C10 - DS

Using EXPLICIT Mode –The EXPLICIT mode query must be written in a specific way so that the additional information about the required XML, such as expected nesting in the XML, is explicitly specified as part of the query. –Because you describe the XML you want as part of the query in EXPLICIT mode, you must ensure that the generated XML is well formed and valid. C10 - DS

Using EXPLICIT Mode –The EXPLICIT mode transforms the rowset that results from the query execution into an XML document. In order for EXPLICIT mode to produce the XML document, the rowset must have a specific format. This requires that you write the SELECT query to produce the rowset, the universal table, with a specific format so the processing logic can then produce the XML you want. –First, the query must produce the following two metadata columns: The first column must provide the tag number, integer type, of the current element, and the column name must be Tag. Your query must provide a unique tag number for each element that will be constructed from the rowset. The second column must provide a tag number of the parent element, and this column name must be Parent. In this way, the Tag and the Parent column provide hierarchy information. C10 - DS

Using EXPLICIT Mode –Exemplu: universal table C10 - DS

Using EXPLICIT Mode –Specifying Column Names in a Universal Table –When writing EXPLICIT mode queries, column names in the resulting rowset must be specified by using this format. They provide transformation information including element and attribute names and other additional information, specified by using directives. –This is the general format: – ElementName!TagNumber!AttributeName!Directive – Following is the description of the parts of the format. –ElementName –Is the resulting generic identifier of the element. For example, if Customers is specified as ElementName, the element is generated. C10 - DS

Using EXPLICIT Mode –TagNumber –Is a unique tag value assigned to an element. This value, with the help of the two metadata columns, Tag and Parent, determines the nesting of the elements in the resulting XML. –AttributeName –Provides the name of the attribute to construct in the specified ElementName. This is the behavior if Directive is not specified. –If Directive is specified and it is xml, cdata, or element, this value is used to construct an element child of ElementName, and the column value is added to it. –If you specify the Directive, the AttributeName can be empty. For example, ElementName!TagNumber!!Directive. In this case, the column value is directly contained by the ElementName. C10 - DS

Using EXPLICIT Mode –Directive –Directive is optional. –You can use Directive to indicate how to map the string data to XML. The hide, element, elementxsinil, xml, xmltext, and cdata keywords can be used as the Directive. The hide directive hides the node. This is useful when you retrieve values only for sorting purposes, but you do not want them in the resulting XML. –The element directive generates a contained element instead of an attribute. For NULL column values, no element is generated. If you want an element generated for null column values, you can specify the elementxsinil directive. This will generate an element that has the attribute xsi:nil=TRUE. C10 - DS

Using EXPLICIT Mode –If the Directive and the AttributeName is not specified, for example, Customer!1, an element directive is implied, such as Customer!1!!element, and column data is contained in the ElementName. –If AttributeName is specified, the tag name is replaced by the specified name. Otherwise, the attribute is appended to the current list of attributes of the enclosing elements by putting the content at the beginning of the containment without entity encoding. The column with this directive must be a text type, such as varchar, nvarchar, char, nchar, text, or ntext. This directive can be used only with hide. C10 - DS

Exemple EXPLICIT select 1 as tag, null as parent, cods as [sectie!1!codsectie], denumires as [sectie!1!denumires] from sectii => tag parent sectie!1!codsectie sectie!1!denumires NULL 1 Matematicã 1 NULL 2 Informaticã 1 NULL 3 Matematicã-Informaticã 1 NULL 4 Matematicã economicã 1 NULL 5 Matematici aplicate 1 NULL 6 Tehnologie Informaticã C10 - DS

Exemple EXPLICIT select 1 as tag, null as parent, cods as [sectie!1!codsectie], denumires as [sectie!1!denumires] from sectii for xml explicit => C10 - DS

Exemple EXPLICIT select 1 as tag, null as parent, cods as [sectie!1!codsectie], denumires as [sectie!1!denumires!element] from sectii for xml explicit => Matematicã Informaticã Matematicã-Informaticã (...) C10 - DS

Exemple EXPLICIT select 1 as tag, null as parent, cods as [sectie!1!codsectie], denumires as [sectie!1!denumires], null as [student!2!nrmatricol], null as [student!2!nume], null as [student!2!grupa] from sectii union all select 2 as tag, 1 as parent, cods as [sectie!1!codsectie], null as [sectie!1!denumires], nrmatricol as [student!2!nrmatricol], nume as [student!2!nume], grupa as [student!2!grupa] from studenti C10 - DS

Exemple EXPLICIT => C10 - DS

Exemple EXPLICIT select 1 as tag, null as parent, cods as [sectie!1!codsectie], denumires as [sectie!1!denumires], null as [student!2!nrmatricol], null as [student!2!nume], null as [student!2!grupa] from sectii union all select 2 as tag, 1 as parent, cods as [sectie!1!codsectie], null as [sectie!1!denumires], nrmatricol as [student!2!nrmatricol], nume as [student!2!nume], grupa as [student!2!grupa] from studenti for xml explicit C10 - DS

Exemple EXPLICIT (rezultat exemplul anterior) (...) C10 - DS

Exemple EXPLICIT select 1 as tag, null as parent, cods as [sectie!1!codsectie], denumires as [sectie!1!denumires], null as [student!2!nrmatricol], null as [student!2!nume], null as [student!2!grupa] from sectii union all select 2 as tag, 1 as parent, cods as [sectie!1!codsectie], null as [sectie!1!denumires], nrmatricol as [student!2!nrmatricol], nume as [student!2!nume], grupa as [student!2!grupa] from studenti order by [sectie!1!codsectie], [sectie!1!denumires] desc for xml explicit C10 - DS

Exemple EXPLICIT => C10 - DS

Exemple EXPLICIT (rezultat exemplul anterior) (...) (...) (...) C10 - DS

Exemple EXPLICIT select 1 as tag, null as parent, cods as [sectie!1!codsectie], denumires as [sectie!1!denumires], null as [student!2!nrmatricol], null as [student!2!nume], null as [student!2!grupa], null as [rezultat!3!disciplina], null as [rezultat!3!nota] from sectii union all select 2 as tag, 1 as parent, cods as [sectie!1!codsectie], null as [sectie!1!denumires], nrmatricol as [student!2!nrmatricol], nume as [student!2!nume], grupa as [student!2!grupa], null as [rezultat!3!disciplina], null as [rezultat!3!nota] from studenti C10 - DS union all select 3 as tag, 2 as parent, st.cods as [sectie!1!codsectie], null as [sectie!1!denumires], r.nrmatricol as [student!2!nrmatricol], null as [student!2!nume], null as [student!2!grupa], disciplina as [rezultat!3!disciplina], nota as [rezultat!3!nota] from studenti as st inner join rezultate as r on r.nrmatricol = st.nrmatricol order by [sectie!1!codsectie], [sectie!1!denumires] desc, [student!2!nrmatricol], [student!2!nume] desc for xml explicit

Exemple EXPLICIT (rezultat exemplul anterior, fara FOR XML) tag parent codsectie denumires nrmatricol nume grupa disciplina nota NULL 1 Matematicã NULL NULL NULL NULL NULL NULL 7587 Huluban Ovidiu 141 NULL NULL NULL 7587 NULL NULL MA NULL 7587 NULL NULL MI NULL 8043 Pop Daniela Ioana 141 NULL NULL NULL 8043 NULL NULL MG NULL 8070 Ulici Amalia Laura 141 NULL NULL NULL 8481 Alexandru Ionel 141 NULL NULL NULL 8481 NULL NULL MA NULL 8481 NULL NULL MG (...) 1 NULL 2 Informaticã NULL NULL NULL NULL NULL NULL 7019 Damian Mircea 224 NULL NULL NULL 7019 NULL NULL MA NULL 7019 NULL NULL MA NULL 7230 Cioca Nicolae Valentin 243 NULL NULL NULL 7255 Iurcu Florin-Daniel 231 NULL NULL NULL 7255 NULL NULL MA NULL 7674 Guzic Bogdan-Ovidiu 231 NULL NULL NULL 7892 Damian Cristina Ioana 233 NULL NULL NULL 7908 Ilovan Cristian Marian 232 NULL NULL NULL 7908 NULL NULL MA C10 - DS

Exemple EXPLICIT (rezultat exemplul anterior, cu FOR XML) (...) (...) C10 - DS

Exemple EXPLICIT select 1 as tag, null as parent, cods as [sectie!1!codsectie], denumires as [sectie!1!denumires], null as [disciplina!2!codd], null as [disciplina!2!denumired], null as [student!3!nrmatricol], null as [student!3!nume] from sectii union all select 2 as tag, 1 as parent, p.cods as [sectie!1!codsectie], null as [sectie!1!denumires], d.codd as [disciplina!2!codd], d.denumired as [disciplina!2!denumired], null as [student!3!nrmatricol], null as [student!3!nume] from planinv as p inner join discipline as d on d.codd = p.codd C10 - DS union all select 3 as tag, 1 as parent, cods as [sectie!1!codsectie], null as [sectie!1!denumires], null as [disciplina!2!codd], null as [disciplina!2!denumired], nrmatricol as [student!3!nrmatricol], nume as [student!3!nume] from studenti order by [sectie!1!codsectie], [sectie!1!denumires] desc, [disciplina!2!codd] desc, [student!3!nrmatricol] for xml explicit

C10 - DS

Exemple EXPLICIT (rezultat exemplul anterior, cu FOR XML) (...) (...) (...) (...) C10 - DS

Using PATH Mode –PATH mode, together with the ability to write nested FOR XML queries and the TYPE directive to return xml type instances, allows you to write queries with less complexity. –In PATH mode, column names or column aliases are treated as XPath expressions. These expressions indicate how the values are being mapped to XML. Each XPath expression is a relative XPath that provides the item type., such as the attribute, element, and scalar value, and the name and hierarchy of the node that will be generated relative to the row element. C10 - DS

Using PATH Mode –Columns without a Name –Any column without a name will be inlined. For example, computed columns or nested scalar queries that do not specify column alias will generate columns without any name. If the column is of xml type, the content of that data type instance is inserted. Otherwise, the column content is inserted as a text node. SELECT 2+2 FOR XML PATH –Produce this XML. By default, for each row in the rowset, a element is generated in the resulting XML. This is the same as RAW mode. 4 –The following query returns a three-column rowset. The third column without a name has XML data. The PATH mode inserts an instance of the xml type. C10 - DS

Using PATH Mode –Columns with a Name –Following are the specific conditions in which rowset columns with a name are mapped, case-sensitive, to the resulting XML: –Column name starts with an at sign –Column name does not start with an at sign –Column name does not start with an at and contains a slash mark (/) –Several columns share the same prefix –One column has a different name C10 - DS

Exemple PATH select * from studenti for xml path => C10 - DS Lupu Teodor Grigore T00:00: Hodis George-Raul Farcas Vasile-Sebastian (...)

Exemple PATH select NrMatricol as CodS as Nume, Grupa from studenti for xml path('student') => C10 - DS Lupu Teodor Grigore 132 Maguran Florin-Ciprian 132 Milasan Cristian Dorel 132 (...)

Exemple PATH select NrMatricol as CodS as Nume, Grupa as 'detalii/grupa', datan as 'detalii/datanasterii' from studenti for xml path('student') => C10 - DS Lupu Teodor Grigore T00:00:00 Maguran Florin-Ciprian T00:00:00 (...)

Exemple PATH select st.nrmatricol, st.nume, r.disciplina, r.nota from studenti as st inner join rezultate as r on r.nrmatricol = st.nrmatricol for xml path('student') => C10 - DS 154 Farcas Vasile-Sebastian MA Anghelcev Daniel MO Anghelcev Daniel MI (...)

Exemple PATH select st.nrmatricol, st.nume, (select disciplina, nota from rezultate as r where r.nrmatricol = st.nrmatricol for xml path('rezultat'), type) as note from studenti as st for xml path('student') => C10 - DS 110 Lupu Teodor Grigore (...) 154 Farcas Vasile-Sebastian MA (...) 525 Anghelcev Daniel MO MI

Exemple PATH select nrmatricol, cods as 'data()', nume as '*', grupa as 'detalii/grupa' from studenti for xml path('student') => 110 4Lupu Teodor Grigore Maguran Florin-Ciprian 132 (...) C10 - DS

Exemple PATH select codd as "data()" from discipline for xml path ('') => MA001 MA002 MA003 MA004 MA005 MG001 MG002 MG003 MG020 MI001 MI003 MI004 MI006 MI011 MI039 MI074 MI081 MI082 MO001 MO002 MO030 C10 - DS

Exemple PATH select st.nrmatricol, st.nume, (select disciplina as "data()" from rezultate as r where r.nrmatricol = st.nrmatricol for xml path('')) as note from studenti as st for xml path => 110 Lupu Teodor Grigore (...) 154 Farcas Vasile-Sebastian MA001 (...) 525 Anghelcev Daniel MO001 MI006 (...) C10 - DS

Next 11 –Oracle - OR C10 - DS