MICROSOFT SQL SERVER &ORACLE 11G XMLBySunny Okoro
ContentsMICROSOFT SQL SERVER.................................................................................................
MICROSOFT SQL SERVERDevelopment ToolsDatabase Platform: Microsoft SQL Server 2008R2
/*inserting data from query into a table from product.xml*/Use AdventureWorksGocreate table prodxml(productnumber xml,quan...
/*Using Value() method to reterive scalar value from an XML document */declare @s xmlselect @s = <Student StudentID = "098...
Use AdventureWorksDWGoCREATE TABLE CUSTOMER1(RECORD_ID INT IDENTITY PRIMARY KEY,CUSTOMER_ID INT,FIRST_NAME NVARCHAR(50),MI...
VALUES( (SELECT CustomerKey FROM DBO.DimCustomer WHERE CustomerKey =11000),(SELECT FIRSTNAME FROM DBO.DimCustomer WHERE Cu...
set city = Rockhamptonwherecustomer_id = 11000;goupdate dbo.CUSTOMER1setstatename = Queenslandwherecustomer_id = 11000;gou...
goupdate dbo.CUSTOMER1setcountycode = USwherecustomer_id = 11062;goupdate dbo.CUSTOMER1setpostalcode = 97205wherecustomer_...
insert into CUSTOMER2(Record_id, customer_data) SELECT 1,<customer record_Id = "1"><customer geographykey ="26" city ="Roc...
<customerFirstName="Cameron"LastName="Patterson"MiddleName="M"CustomerKey="25790"BirthDate="1953-09-10T00:00:00"Gender="M"...
<GeographyCity="Stoke-on-Trent"StateCode="ENG"StateName="England"CountryCode="GB" /></customer><customerFirstName="Theodor...
</Geography></customer><customerFirstName="Bailey"LastName="Allen"MiddleName="F"CustomerKey="27218"BirthDate="1957-11-07T0...
Geography.CountryRegionCode as CountryCode,Territory.SalesTerritoryCountry AS TerritoryCountry, Territory.SalesTerritoryRe...
</Geography></customer><customer FirstName="Julio" LastName="Ruiz" CustomerKey="11005"BirthDate="1965-08-05T00:00:00" Gend...
<rowFirstName="Eugene"LastName="Huang"MiddleName="L"CustomerKey="11001"BirthDate="1965-05-14T00:00:00"Gender="M"MaritalSta...
useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.Birth...
<CustomerFirstName="Eugene"LastName="Zeng"CustomerKey="24025"BirthDate="1960-01-02T00:00:00"Gender="M"MaritalStatus="M"Cit...
useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.Birth...
<Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></row><row><FirstName>Eugene</FirstName><LastName>He</La...
selectcustomer.CustomerKey as[@custno],customer.FirstName as [Customer/customer]fromdbo.DimCustomer as customerwherecustom...
oncustomer.GeographyKey = Geography.GeographyKeyinner joindbo.DimSalesTerritory TerritoryonTerritory.salesterritorykey = G...
<LastName>Torres</LastName><CustomerKey>11002</CustomerKey><BirthDate>1965-08-12T00:00:00</BirthDate><Gender>M</Gender><Ma...
dbo.DimCustomer customeroncustomer.GeographyKey =Geography.GeographyKeyFORXMLPATH(CUSTOMER),ROOT(CUSTOMER)CUSTOMER><CUSTOM...
<BirthDate>1965-05-14T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>S</MaritalStatus><City>Seaford</City><StateCode...
c.TotalChildren, s.ProductKey, s.Freight, s.TaxAmt, s.SalesOrderNumber,s.UnitPrice, s.ExtendedAmount, s.UnitPriceDiscountP...
FORXMLRAW(SALES),ELEMENTSXSINIL,ROOT(REPORT)<REPORTxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SALES><FirstName...
ORACLE 11GDevelopment ToolsDatabase Platform: ORACLE 11GApplications: Oracle SQL Developer
SQL>desc studentName Null? Type----------------------------------------- -------- -------------------STUDENT_ID NOT NULL N...
<STUDENT STUDENT_ID="102"><STUDENT_NAME>Fred,Crocitto</STUDENT_NAME><ADDRESS>101-09 120thSt.</ADDRESS></STUDENT><STUDENT S...
STUDENT_ID----------DT-----------------------------------------------------------------999<?xml version = "1.0"?><student>...
ID NOT NULL NUMBEREMPLOYEE NOT NULL PUBLIC.XMLTYPESQL> insert into employeex2 VALUES(908997,xmltype(<?xml version="1.0" st...
---------------------------------------------------------<?xml version="1.0" standalone ="no"?><employee><emp><name>Rubby ...
<?xml version="1.0" standalone ="yes"?><employee><emp><name> Liz Benson </name></emp></employee>SQL> delete employeex2 whe...
Upcoming SlideShare
Loading in …5
×

Relational / XML DB -SQL Server & Oracle Database

641 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
641
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Relational / XML DB -SQL Server & Oracle Database

  1. 1. MICROSOFT SQL SERVER &ORACLE 11G XMLBySunny Okoro
  2. 2. ContentsMICROSOFT SQL SERVER...............................................................................................................................2ORACLE 11G................................................................................................................................................11
  3. 3. MICROSOFT SQL SERVERDevelopment ToolsDatabase Platform: Microsoft SQL Server 2008R2
  4. 4. /*inserting data from query into a table from product.xml*/Use AdventureWorksGocreate table prodxml(productnumber xml,quantity xml,price xml)insert into prodxml(productnumber,quantity, price)Selectg.value(@PRODNUMBER, nvarchar(10)) as Productnumber,g.value(@quantity, nvarchar(10)) as Quantity,g.value(@price, nvarchar(20)) as PriceFROM( select cast (bulkcolumn as xml)as datafrom openrowset(bulk c:tempproduct.xml, single_blob)as g)hCross apply data.nodes(/PRODUCT/PRODUCT) c(g)Select * from prodxml
  5. 5. /*Using Value() method to reterive scalar value from an XML document */declare @s xmlselect @s = <Student StudentID = "0989" StudentSNN="409569090" />select@s.value((Student/@StudentID)[1], CHAR(8)) as STUDENTID,@s.value((Student/@StudentSNN)[1],char(12)) as STUDENTSNNSTUDENTID STUDENTSNN989 409569090/* Using the nodes method to return row set */declare @pid xmlselect @pid =<PRODUCT><PRODNUMBER> 190 </PRODNUMBER><PRODNUMBER> 180 </PRODNUMBER><PRODNUMBER> 170 </PRODNUMBER><PRODNUMBER> 160 </PRODNUMBER><PRODNUMBER> 150 </PRODNUMBER><PRODNUMBER> 140 </PRODNUMBER><PRODNUMBER> 120 </PRODNUMBER></PRODUCT>select a.value(., int) as product_numberfrom @pid.nodes(/PRODUCT/PRODNUMBER)b(a)product_number190180170160150140120/* Joining XML nodews with relational tables */
  6. 6. Use AdventureWorksDWGoCREATE TABLE CUSTOMER1(RECORD_ID INT IDENTITY PRIMARY KEY,CUSTOMER_ID INT,FIRST_NAME NVARCHAR(50),MIDDLE_NAME NVARCHAR(50),LAST_NAME NVARCHAR(50));GOCREATE TABLE CUSTOMER2(RECORD_ID INT,CUSTOMER_DATA XML);Alter table customer1addgeographykey char(20);Alter table customer1add city nvarchar(30);Alter table customer1addstatenamenvarchar(50);Alter table customer1addstatecodenvarchar(3);Alter table customer1addcountycodenvarchar(3);Alter table customer1add POSTALCODE nvarchar(15);Update customer1setINSERT INTO CUSTOMER1(CUSTOMER_ID, FIRST_NAME, MIDDLE_NAME,LAST_NAME)
  7. 7. VALUES( (SELECT CustomerKey FROM DBO.DimCustomer WHERE CustomerKey =11000),(SELECT FIRSTNAME FROM DBO.DimCustomer WHERE CustomerKey =11000),(SELECT MIDDLENAME FROM DBO.DimCustomer WHERE CustomerKey =11000),(SELECT LASTNAME FROM DBO.DimCustomer WHERE CustomerKey =11000));INSERT INTO CUSTOMER1(CUSTOMER_ID, FIRST_NAME, MIDDLE_NAME,LAST_NAME)VALUES( (SELECT CustomerKey FROM DBO.DimCustomer WHERE CustomerKey =11062),(SELECT FIRSTNAME FROM DBO.DimCustomer WHERE CustomerKey =11062),(SELECT MIDDLENAME FROM DBO.DimCustomer WHERE CustomerKey =11062),(SELECT LASTNAME FROM DBO.DimCustomer WHERE CustomerKey =11062));INSERT INTO CUSTOMER1(CUSTOMER_ID, FIRST_NAME, MIDDLE_NAME,LAST_NAME)VALUES( (SELECT CustomerKey FROM DBO.DimCustomer WHERE CustomerKey =11010),(SELECT FIRSTNAME FROM DBO.DimCustomer WHERE CustomerKey =11010),(SELECT MIDDLENAME FROM DBO.DimCustomer WHERE CustomerKey =11010),(SELECT LASTNAME FROM DBO.DimCustomer WHERE CustomerKey =11010));update dbo.CUSTOMER1setgeographykey = (select GeographyKey from dbo.DimCustomer where CustomerKey =11000)wherecustomer_id = 11000update dbo.CUSTOMER1
  8. 8. set city = Rockhamptonwherecustomer_id = 11000;goupdate dbo.CUSTOMER1setstatename = Queenslandwherecustomer_id = 11000;goupdate dbo.CUSTOMER1setstatecode = QLDwherecustomer_id = 11000;goupdate dbo.CUSTOMER1setcountycode = AUwherecustomer_id = 11000;goupdate dbo.CUSTOMER1setpostalcode = 4700wherecustomer_id = 11000;goupdate dbo.CUSTOMER1setgeographykey = (select GeographyKey from dbo.DimCustomer where CustomerKey =11062)wherecustomer_id = 11062;goupdate dbo.CUSTOMER1set city = Portlandwherecustomer_id = 11062;goupdate dbo.CUSTOMER1setstatename = Oregonwherecustomer_id = 11062;goupdate dbo.CUSTOMER1setstatecode = ORwherecustomer_id = 11062;
  9. 9. goupdate dbo.CUSTOMER1setcountycode = USwherecustomer_id = 11062;goupdate dbo.CUSTOMER1setpostalcode = 97205wherecustomer_id = 11062;goupdate dbo.CUSTOMER1setgeographykey = (select GeographyKey from dbo.DimCustomer where CustomerKey =11000)wherecustomer_id = 11010update dbo.CUSTOMER1set city = East Brisbanewherecustomer_id = 11010;goupdate dbo.CUSTOMER1setstatename = Queenslandwherecustomer_id = 11010;goupdate dbo.CUSTOMER1setstatecode = QLDwherecustomer_id = 11010;goupdate dbo.CUSTOMER1setcountycode = AUwherecustomer_id = 11010;goupdate dbo.CUSTOMER1setpostalcode = 4169wherecustomer_id = 11010;go
  10. 10. insert into CUSTOMER2(Record_id, customer_data) SELECT 1,<customer record_Id = "1"><customer geographykey ="26" city ="Rockhampton" statename = "Queensland" statecode="QLD" Country = "Australia" countycode = "AU" POSTALCODE = "4700"/></customer >insert into CUSTOMER2(Record_id, customer_data) SELECT 2,<customer record_Id = "2"><customer geographykey ="547" city ="Portland" statename = "Oregon" statecode ="OR"Country = "United States" countycode = "US" POSTALCODE = "97205"/></customer >insert into CUSTOMER2(Record_id, customer_data) SELECT 3,<customer record_Id = "3"><customer geographykey ="22" city ="East Brisbane" statename = "Queensland" statecode="QLD" Country = "Australia" countycode = "AU" POSTALCODE = "4169"/></customer >useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatusfromdbo.DimCustomer customerorder by NEWID()for xml auto;Results<customerFirstName="Ian"LastName="Watson"MiddleName="G"CustomerKey="26398"BirthDate="1945-06-10T00:00:00"Gender="M"MaritalStatus="M" /><customerFirstName="Jordan"LastName="Green"MiddleName="L"CustomerKey="27915"BirthDate="1974-04-25T00:00:00"Gender="F"MaritalStatus="S" /><customerFirstName="Gregory"LastName="Yuan"CustomerKey="21822"BirthDate="1957-02-26T00:00:00"Gender="M"MaritalStatus="S" /><customerFirstName="Jasmine"LastName="Smith"CustomerKey="28891"BirthDate="1945-11-01T00:00:00"Gender="F"MaritalStatus="S" /><customerFirstName="Shane"LastName="Sai"MiddleName="R"CustomerKey="29374"BirthDate="1965-05-21T00:00:00"Gender="M"MaritalStatus="M" />
  11. 11. <customerFirstName="Cameron"LastName="Patterson"MiddleName="M"CustomerKey="25790"BirthDate="1953-09-10T00:00:00"Gender="M"MaritalStatus="M" /><customerFirstName="Bradley"LastName="Rai"CustomerKey="19100"BirthDate="1971-06-01T00:00:00"Gender="M"MaritalStatus="M" /><customerFirstName="Isaiah"LastName="Roberts"MiddleName="M"CustomerKey="27211"BirthDate="1955-10-12T00:00:00"Gender="M"MaritalStatus="M" /><customerFirstName="Stacy"LastName="Serrano"CustomerKey="24613"BirthDate="1970-09-23T00:00:00"Gender="F"MaritalStatus="M" /><customerFirstName="Eugene"LastName="Zhao"CustomerKey="12328"BirthDate="1950-03-18T00:00:00"Gender="M"MaritalStatus="S" /><customerFirstName="Noah"LastName="Nelson"CustomerKey="16835"BirthDate="1933-10-14T00:00:00"Gender="M"MaritalStatus="M" />RESULTS (ABRIDGED)useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatus,Geography.City, Geography.StateProvinceCode as StateCode, Geography.StateProvinceNameAS StateName,Geography.CountryRegionCode as CountryCodefromdbo.DimCustomer customerinner joindbo.DimGeography Geographyoncustomer.GeographyKey = Geography.GeographyKeyorder by NEWID()for xml auto;<customerFirstName="Kellie"LastName="Dominguez"MiddleName="E"CustomerKey="17244"BirthDate="1972-02-25T00:00:00"Gender="F"MaritalStatus="M"><GeographyCity="Findon"StateCode="SA"StateName="SouthAustralia"CountryCode="AU" /></customer><customerFirstName="Hector"LastName="Ruiz"CustomerKey="27592"BirthDate="1967-11-27T00:00:00"Gender="M"MaritalStatus="S"><GeographyCity="Newcastle"StateCode="NSW"StateName="New SouthWales"CountryCode="AU" /></customer><customerFirstName="Joseph"LastName="Taylor"MiddleName="T"CustomerKey="12289"BirthDate="1968-03-23T00:00:00"Gender="M"MaritalStatus="S">
  12. 12. <GeographyCity="Stoke-on-Trent"StateCode="ENG"StateName="England"CountryCode="GB" /></customer><customerFirstName="Theodore"LastName="Moreno"MiddleName="C"CustomerKey="20872"BirthDate="1968-02-21T00:00:00"Gender="M"MaritalStatus="S"><GeographyCity="Gateshead"StateCode="ENG"StateName="England"CountryCode="GB" /></customer><customerFirstName="Roger"LastName="Sharma"MiddleName="L"CustomerKey="19454"BirthDate="1967-08-17T00:00:00"Gender="M"MaritalStatus="M"><GeographyCity="Neunkirchen"StateCode="SL"StateName="Saarland"CountryCode="DE" />RESULTS (ABRIDGED)useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatus,Geography.City, Geography.StateProvinceCode as StateCode, Geography.StateProvinceNameAS StateName,Geography.CountryRegionCode as CountryCode,Territory.SalesTerritoryCountry AS TerritoryCountry, Territory.SalesTerritoryRegion as Region,Territory.SalesTerritoryGroup as TerritoryGroupfromdbo.DimCustomer customerinner joindbo.DimGeography Geographyoncustomer.GeographyKey = Geography.GeographyKeyinner joindbo.DimSalesTerritory TerritoryonTerritory.salesterritorykey = Geography.salesterritorykeyorder by NEWID()for xml auto;<customerFirstName="Wayne"LastName="Nara"MiddleName="C"CustomerKey="23869"BirthDate="1970-03-15T00:00:00"Gender="M"MaritalStatus="M"><GeographyCity="Ballard"StateCode="WA"StateName="Washington"CountryCode="US"><TerritoryTerritoryCountry="UnitedStates"Region="Northwest"TerritoryGroup="North America" />
  13. 13. </Geography></customer><customerFirstName="Bailey"LastName="Allen"MiddleName="F"CustomerKey="27218"BirthDate="1957-11-07T00:00:00"Gender="F"MaritalStatus="M"><GeographyCity="SantaMonica"StateCode="CA"StateName="California"CountryCode="US"><TerritoryTerritoryCountry="UnitedStates"Region="Southwest"TerritoryGroup="North America" /></Geography></customer><customerFirstName="Garrett"LastName="Sanchez"MiddleName="E"CustomerKey="15885"BirthDate="1946-05-18T00:00:00"Gender="M"MaritalStatus="S"><GeographyCity="SedroWoolley"StateCode="WA"StateName="Washington"CountryCode="US"><TerritoryTerritoryCountry="UnitedStates"Region="Northwest"TerritoryGroup="North America" /></Geography></customer><customerFirstName="Jackson"LastName="Alexander"CustomerKey="20876"BirthDate="1968-04-27T00:00:00"Gender="M"MaritalStatus="S"><GeographyCity="Darmstadt"StateCode="HE"StateName="Hessen"CountryCode="DE"><TerritoryTerritoryCountry="Germany"Region="Germany"TerritoryGroup="Europe" /></Geography></customer><customerFirstName="Katherine"LastName="Allen"CustomerKey="17457"BirthDate="1954-03-27T00:00:00"Gender="F"MaritalStatus="M"><GeographyCity="Burien"StateCode="WA"StateName="Washington"CountryCode="US"><TerritoryTerritoryCountry="UnitedStates"Region="Northwest"TerritoryGroup="North America" /></Geography></customer>RESULTS (ABRIDGED)useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatus,Geography.City, Geography.StateProvinceCode as StateCode, Geography.StateProvinceNameAS StateName,
  14. 14. Geography.CountryRegionCode as CountryCode,Territory.SalesTerritoryCountry AS TerritoryCountry, Territory.SalesTerritoryRegion as Region,Territory.SalesTerritoryGroup as TerritoryGroupfromdbo.DimCustomer customerinner joindbo.DimGeography Geographyoncustomer.GeographyKey = Geography.GeographyKeyinner joindbo.DimSalesTerritory TerritoryonTerritory.salesterritorykey = Geography.salesterritorykeyfor xml auto;<customer FirstName="Eugene" LastName="Huang" MiddleName="L"CustomerKey="11001" BirthDate="1965-05-14T00:00:00" Gender="M"MaritalStatus="S"><Geography City="Seaford" StateCode="VIC" StateName="Victoria"CountryCode="AU"><Territory TerritoryCountry="Australia" Region="Australia"TerritoryGroup="Pacific" /></Geography></customer><customer FirstName="Ruben" LastName="Torres"CustomerKey="11002" BirthDate="1965-08-12T00:00:00" Gender="M"MaritalStatus="M"><Geography City="Hobart" StateCode="TAS" StateName="Tasmania"CountryCode="AU"><Territory TerritoryCountry="Australia" Region="Australia"TerritoryGroup="Pacific" /></Geography></customer><customer FirstName="Christy" LastName="Zhu" CustomerKey="11003"BirthDate="1968-02-15T00:00:00" Gender="F" MaritalStatus="S"><Geography City="North Ryde" StateCode="NSW" StateName="NewSouth Wales" CountryCode="AU"><Territory TerritoryCountry="Australia" Region="Australia"TerritoryGroup="Pacific" /></Geography></customer><customer FirstName="Elizabeth" LastName="Johnson"CustomerKey="11004" BirthDate="1968-08-08T00:00:00" Gender="F"MaritalStatus="S"><Geography City="Wollongong" StateCode="NSW" StateName="NewSouth Wales" CountryCode="AU"><Territory TerritoryCountry="Australia" Region="Australia"TerritoryGroup="Pacific" />
  15. 15. </Geography></customer><customer FirstName="Julio" LastName="Ruiz" CustomerKey="11005"BirthDate="1965-08-05T00:00:00" Gender="M" MaritalStatus="S"><Geography City="East Brisbane" StateCode="QLD"StateName="Queensland" CountryCode="AU"><Territory TerritoryCountry="Australia" Region="Australia"TerritoryGroup="Pacific" /></Geography></customer>RESULTS (ABRIDGED)useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatus,Geography.City, Geography.StateProvinceCode as StateCode, Geography.StateProvinceNameAS StateName,Geography.CountryRegionCode as CountryCode,Territory.SalesTerritoryCountry AS TerritoryCountry, Territory.SalesTerritoryRegion as Region,Territory.SalesTerritoryGroup as TerritoryGroupfromdbo.DimCustomer customerinner joindbo.DimGeography Geographyoncustomer.GeographyKey = Geography.GeographyKeyinner joindbo.DimSalesTerritory TerritoryonTerritory.salesterritorykey = Geography.salesterritorykeyfor xml RAW;
  16. 16. <rowFirstName="Eugene"LastName="Huang"MiddleName="L"CustomerKey="11001"BirthDate="1965-05-14T00:00:00"Gender="M"MaritalStatus="S"City="Seaford"StateCode="VIC"StateName="Victoria"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><rowFirstName="Ruben"LastName="Torres"CustomerKey="11002"BirthDate="1965-08-12T00:00:00"Gender="M"MaritalStatus="M"City="Hobart"StateCode="TAS"StateName="Tasmania"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><rowFirstName="Christy"LastName="Zhu"CustomerKey="11003"BirthDate="1968-02-15T00:00:00"Gender="F"MaritalStatus="S"City="North Ryde"StateCode="NSW"StateName="New SouthWales"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><rowFirstName="Elizabeth"LastName="Johnson"CustomerKey="11004"BirthDate="1968-08-08T00:00:00"Gender="F"MaritalStatus="S"City="Wollongong"StateCode="NSW"StateName="New SouthWales"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><rowFirstName="Julio"LastName="Ruiz"CustomerKey="11005"BirthDate="1965-08-05T00:00:00"Gender="M"MaritalStatus="S"City="EastBrisbane"StateCode="QLD"StateName="Queensland"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><rowFirstName="Janet"LastName="Alvarez"MiddleName="G"CustomerKey="11006"BirthDate="1965-12-06T00:00:00"Gender="F"MaritalStatus="S"City="Matraville"StateCode="NSW"StateName="New SouthWales"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><rowFirstName="Marco"LastName="Mehta"CustomerKey="11007"BirthDate="1964-05-09T00:00:00"Gender="M"MaritalStatus="M"City="Warrnambool"StateCode="VIC"StateName="Victoria"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><rowFirstName="Rob"LastName="Verhoff"CustomerKey="11008"BirthDate="1964-07-07T00:00:00"Gender="F"MaritalStatus="S"City="Bendigo"StateCode="VIC"StateName="Victoria"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><rowFirstName="Shannon"LastName="Carlson"MiddleName="C"CustomerKey="11009"BirthDate="1964-04-01T00:00:00"Gender="M"MaritalStatus="S"City="HerveyBay"StateCode="QLD"StateName="Queensland"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><rowFirstName="Jacquelyn"LastName="Suarez"MiddleName="C"CustomerKey="11010"BirthDate="1964-02-06T00:00:00"Gender="F"MaritalStatus="S"City="East Brisbane"StateCode="QLD"RESULTS (ABRIDGED)
  17. 17. useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatus,Geography.City, Geography.StateProvinceCode as StateCode, Geography.StateProvinceName AS StateName,Geography.CountryRegionCode as CountryCode,Territory.SalesTerritoryCountry AS TerritoryCountry, Territory.SalesTerritoryRegion as Region, Territory.SalesTerritoryGroup as TerritoryGroupfromdbo.DimCustomer customerinner joindbo.DimGeography Geographyoncustomer.GeographyKey = Geography.GeographyKeyinner joindbo.DimSalesTerritory TerritoryonTerritory.salesterritorykey = Geography.salesterritorykeywherecustomer.FirstName = Eugenefor xml RAW(Customer), Root(Customer);<Customer><CustomerFirstName="Eugene"LastName="Ma"MiddleName="A"CustomerKey="24374"BirthDate="1965-10-13T00:00:00"Gender="M"MaritalStatus="S"City="Silverwater"StateCode="NSW"StateName="New SouthWales"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><CustomerFirstName="Eugene"LastName="She"MiddleName="L"CustomerKey="20998"BirthDate="1978-01-03T00:00:00"Gender="M"MaritalStatus="M"City="Caloundra"StateCode="QLD"StateName="Queensland"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><CustomerFirstName="Eugene"LastName="He"MiddleName="L"CustomerKey="13645"BirthDate="1970-09-16T00:00:00"Gender="M"MaritalStatus="S"City="Hawthorne"StateCode="QLD"StateName="Queensland"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><CustomerFirstName="Eugene"LastName="Gao"CustomerKey="29464"BirthDate="1977-09-05T00:00:00"Gender="M"MaritalStatus="S"City="Rockhampton"StateCode="QLD"StateName="Queensland"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><CustomerFirstName="Eugene"LastName="Liang"CustomerKey="13972"BirthDate="1965-04-02T00:00:00"Gender="M"MaritalStatus="S"City="Perth"StateCode="SA"StateName="SouthAustralia"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><CustomerFirstName="Eugene"LastName="Huang"MiddleName="L"CustomerKey="11001"BirthDate="1965-05-14T00:00:00"Gender="M"MaritalStatus="S"City="Seaford"StateCode="VIC"StateName="Victoria"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"TerritoryGroup="Pacific" /><CustomerFirstName="Eugene"LastName="Li"MiddleName="A"CustomerKey="15283"BirthDate="1972-11-22T00:00:00"Gender="M"MaritalStatus="S"City="Cliffside"StateCode="BC"StateName="BritishColumbia"CountryCode="CA"TerritoryCountry="Canada"Region="Canada"TerritoryGroup="North America" /><CustomerFirstName="Eugene"LastName="Zheng"CustomerKey="23960"BirthDate="1975-12-07T00:00:00"Gender="M"MaritalStatus="S"City="Frankfurt"StateCode="HE"StateName="Hessen"CountryCode="DE"TerritoryCountry="Germany"Region="Germany"TerritoryGroup="Europe" />
  18. 18. <CustomerFirstName="Eugene"LastName="Zeng"CustomerKey="24025"BirthDate="1960-01-02T00:00:00"Gender="M"MaritalStatus="M"City="Hamburg"StateCode="HE"StateName="Hessen"CountryCode="DE"TerritoryCountry="Germany"Region="Germany"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Wu"MiddleName="P"CustomerKey="22414"BirthDate="1943-08-08T00:00:00"Gender="M"MaritalStatus="S"City="Hamburg"StateCode="HE"StateName="Hessen"CountryCode="DE"TerritoryCountry="Germany"Region="Germany"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Lu"MiddleName="N"CustomerKey="14187"BirthDate="1952-09-24T00:00:00"Gender="M"MaritalStatus="M"City="Hamburg"StateCode="HE"StateName="Hessen"CountryCode="DE"TerritoryCountry="Germany"Region="Germany"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Wang"CustomerKey="18146"BirthDate="1944-06-28T00:00:00"Gender="M"MaritalStatus="S"City="Hamburg"StateCode="HH"StateName="Hamburg"CountryCode="DE"TerritoryCountry="Germany"Region="Germany"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Sun"MiddleName="J"CustomerKey="19040"BirthDate="1944-09-04T00:00:00"Gender="M"MaritalStatus="M"City="Paderborn"StateCode="HH"StateName="Hamburg"CountryCode="DE"TerritoryCountry="Germany"Region="Germany"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Chen"MiddleName="L"CustomerKey="28376"BirthDate="1967-10-08T00:00:00"Gender="M"MaritalStatus="S"City="Saarlouis"StateCode="SL"StateName="Saarland"CountryCode="DE"TerritoryCountry="Germany"Region="Germany"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Lin"CustomerKey="28737"BirthDate="1972-03-22T00:00:00"Gender="M"MaritalStatus="S"City="Orleans"StateCode="45"StateName="Loiret"CountryCode="FR"TerritoryCountry="France"Region="France"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Guo"MiddleName="R"CustomerKey="15700"BirthDate="1952-11-19T00:00:00"Gender="M"MaritalStatus="M"City="Paris"StateCode="75"StateName="Seine(Paris)"CountryCode="FR"TerritoryCountry="France"Region="France"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Zhang"MiddleName="C"CustomerKey="27887"BirthDate="1960-09-07T00:00:00"Gender="M"MaritalStatus="S"City="Paris"StateCode="75"StateName="Seine(Paris)"CountryCode="FR"TerritoryCountry="France"Region="France"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Xu"MiddleName="A"CustomerKey="14208"BirthDate="1947-08-22T00:00:00"Gender="M"MaritalStatus="S"City="Gloucestershire"StateCode="ENG"StateName="England"CountryCode="GB"TerritoryCountry="United Kingdom"Region="United Kingdom"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Zhao"CustomerKey="12328"BirthDate="1950-03-18T00:00:00"Gender="M"MaritalStatus="S"City="London"StateCode="ENG"StateName="England"CountryCode="GB"TerritoryCountry="United Kingdom"Region="United Kingdom"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Liu"CustomerKey="14712"BirthDate="1971-11-22T00:00:00"Gender="M"MaritalStatus="S"City="London"StateCode="ENG"StateName="England"CountryCode="GB"TerritoryCountry="United Kingdom"Region="United Kingdom"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Ye"MiddleName="E"CustomerKey="11609"BirthDate="1976-06-26T00:00:00"Gender="M"MaritalStatus="S"City="York"StateCode="ENG"StateName="England"CountryCode="GB"TerritoryCountry="United Kingdom"Region="United Kingdom"TerritoryGroup="Europe" /><CustomerFirstName="Eugene"LastName="Yang"CustomerKey="17676"BirthDate="1957-06-03T00:00:00"Gender="M"MaritalStatus="M"City="Bellflower"StateCode="CA"StateName="California"CountryCode="US"TerritoryCountry="United States"Region="Southwest"TerritoryGroup="North America" /><CustomerFirstName="Eugene"LastName="Zhu"MiddleName="D"CustomerKey="13060"BirthDate="1975-06-09T00:00:00"Gender="M"MaritalStatus="M"City="Concord"StateCode="CA"StateName="California"CountryCode="US"TerritoryCountry="United States"Region="Southwest"TerritoryGroup="North America" /></Customer>
  19. 19. useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatus,Geography.City, Geography.StateProvinceCode as StateCode, Geography.StateProvinceName AS StateName,Geography.CountryRegionCode as CountryCode,Territory.SalesTerritoryCountry AS TerritoryCountry, Territory.SalesTerritoryRegion as Region, Territory.SalesTerritoryGroup as TerritoryGroupfromdbo.DimCustomer customerinner joindbo.DimGeography Geographyoncustomer.GeographyKey = Geography.GeographyKeyinner joindbo.DimSalesTerritory TerritoryonTerritory.salesterritorykey = Geography.salesterritorykeywherecustomer.FirstName = Eugenefor xml path;<row><FirstName>Eugene</FirstName><LastName>Ma</LastName><MiddleName>A</MiddleName><CustomerKey>24374</CustomerKey><BirthDate>1965-10-13T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>S</MaritalStatus><City>Silverwater</City><StateCode>NSW</StateCode><StateName>New South Wales</StateName><CountryCode>AU</CountryCode><TerritoryCountry>Australia</TerritoryCountry><Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></row><row><FirstName>Eugene</FirstName><LastName>She</LastName><MiddleName>L</MiddleName><CustomerKey>20998</CustomerKey><BirthDate>1978-01-03T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>M</MaritalStatus><City>Caloundra</City><StateCode>QLD</StateCode><StateName>Queensland</StateName><CountryCode>AU</CountryCode><TerritoryCountry>Australia</TerritoryCountry>
  20. 20. <Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></row><row><FirstName>Eugene</FirstName><LastName>He</LastName><MiddleName>L</MiddleName><CustomerKey>13645</CustomerKey><BirthDate>1970-09-16T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>S</MaritalStatus><City>Hawthorne</City><StateCode>QLD</StateCode><StateName>Queensland</StateName><CountryCode>AU</CountryCode><TerritoryCountry>Australia</TerritoryCountry><Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></row><row><FirstName>Eugene</FirstName><LastName>Gao</LastName><CustomerKey>29464</CustomerKey><BirthDate>1977-09-05T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>S</MaritalStatus><City>Rockhampton</City><StateCode>QLD</StateCode><StateName>Queensland</StateName><CountryCode>AU</CountryCode><TerritoryCountry>Australia</TerritoryCountry><Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></row><row><FirstName>Eugene</FirstName><LastName>Liang</LastName><CustomerKey>13972</CustomerKey><BirthDate>1965-04-02T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>S</MaritalStatus><City>Perth</City><StateCode>SA</StateCode><StateName>South Australia</StateName><CountryCode>AU</CountryCode><TerritoryCountry>Australia</TerritoryCountry><Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></row>
  21. 21. selectcustomer.CustomerKey as[@custno],customer.FirstName as [Customer/customer]fromdbo.DimCustomer as customerwherecustomer.FirstName = Eugenefor xml path;<row custno="11001"><Customer><customer>Eugene</customer></Customer></row><row custno="11609"><Customer><customer>Eugene</customer></Customer></row><row custno="12328"><Customer><customer>Eugene</customer></Customer></row><row custno="13060"><Customer><customer>Eugene</customer></Customer></row><row custno="13645"><Customer><customer>Eugene</customer></Customer></row>use AdventureWorksDWgoselect customer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatus,Geography.City, Geography.StateProvinceCode as StateCode, Geography.StateProvinceName AS StateName,Geography.CountryRegionCode as CountryCode,Territory.SalesTerritoryCountry AS TerritoryCountry, Territory.SalesTerritoryRegion as Region, Territory.SalesTerritoryGroup as TerritoryGroupfrom dbo.DimCustomer customerinner joindbo.DimGeography Geography
  22. 22. oncustomer.GeographyKey = Geography.GeographyKeyinner joindbo.DimSalesTerritory TerritoryonTerritory.salesterritorykey = Geography.salesterritorykeyfor XML AUTO, ELEMENTS;<customer><FirstName>Eugene</FirstName><LastName>Huang</LastName><MiddleName>L</MiddleName><CustomerKey>11001</CustomerKey><BirthDate>1965-05-14T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>S</MaritalStatus><Geography><City>Seaford</City><StateCode>VIC</StateCode><StateName>Victoria</StateName><CountryCode>AU</CountryCode><Territory><TerritoryCountry>Australia</TerritoryCountry><Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></Territory></Geography></customer><customer><FirstName>Ruben</FirstName>
  23. 23. <LastName>Torres</LastName><CustomerKey>11002</CustomerKey><BirthDate>1965-08-12T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>M</MaritalStatus><Geography><City>Hobart</City><StateCode>TAS</StateCode><StateName>Tasmania</StateName><CountryCode>AU</CountryCode><Territory><TerritoryCountry>Australia</TerritoryCountry><Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></Territory></Geography></customer>use AdventureWorksDWgoselect customer.CustomerKey as [@CUST_ID], customer.FirstName AS[@FIRST_NAME], customer.LastName AS[@LAST_NAME], customer.MiddleName AS [@MIDDLE_NAME],CONVERT(DATE,customer.BirthDate)AS [@DOB], customer.Gender AS [@GENDER], customer.MaritalStatus AS [@Marital_status],Geography.City as [@CITY],Geography.StateProvinceCode as [@State-Code],Geography.StateProvinceName AS [@State],Geography.CountryRegionCode as[@Country-Code]from(SELECT Territory.SalesTerritoryKey as [@Territory-key], Territory.SalesTerritoryCountry AS [@Territory-Country],Territory.SalesTerritoryRegion as [@Region], Territory.SalesTerritoryGroup as [@TerritoryGroup]FROM dbo.DimSalesTerritory Territory)tinnerjoindbo.DimGeography GeographyonGeography.SalesTerritoryKey = t.[@Territory-key]innerjoin
  24. 24. dbo.DimCustomer customeroncustomer.GeographyKey =Geography.GeographyKeyFORXMLPATH(CUSTOMER),ROOT(CUSTOMER)CUSTOMER><CUSTOMERCUST_ID="11000"FIRST_NAME="Jon"LAST_NAME="Yang"MIDDLE_NAME="V"DOB="1966-04-08"GENDER="M"Marital_status="M"CITY="Rockhampton"State-Code="QLD"State="Queensland"Country-Code="AU" /><CUSTOMERCUST_ID="11001"FIRST_NAME="Eugene"LAST_NAME="Huang"MIDDLE_NAME="L"DOB="1965-05-14"GENDER="M"Marital_status="S"CITY="Seaford"State-Code="VIC"State="Victoria"Country-Code="AU" /><CUSTOMERCUST_ID="11002"FIRST_NAME="Ruben"LAST_NAME="Torres"DOB="1965-08-12"GENDER="M"Marital_status="M"CITY="Hobart"State-Code="TAS"State="Tasmania"Country-Code="AU" /><CUSTOMERCUST_ID="11003"FIRST_NAME="Christy"LAST_NAME="Zhu"DOB="1968-02-15"GENDER="F"Marital_status="S"CITY="NorthRyde"State-Code="NSW"State="New South Wales"Country-Code="AU" /><CUSTOMERCUST_ID="29483"FIRST_NAME="Jésus"LAST_NAME="Navarro"MIDDLE_NAME="L"DOB="1959-12-08"GENDER="M"Marital_status="M"CITY="Paris La Defense"State-Code="92"State="Hauts de Seine"Country-Code="FR" /></CUSTOMER>RESULTS (ABRIDGED)useAdventureWorksDWgoselectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatus,Geography.City, Geography.StateProvinceCode as StateCode, Geography.StateProvinceName AS StateName,Geography.CountryRegionCode as CountryCode,Territory.SalesTerritoryCountry AS TerritoryCountry, Territory.SalesTerritoryRegion as Region, Territory.SalesTerritoryGroup as TerritoryGroupfromdbo.DimCustomer customerinner joindbo.DimGeography Geographyoncustomer.GeographyKey = Geography.GeographyKeyinner joindbo.DimSalesTerritory TerritoryonTerritory.salesterritorykey = Geography.salesterritorykeywherecustomer.FirstName = Eugenefor xml RAW(customer),ELEMENTS<customer><FirstName>Eugene</FirstName><LastName>Huang</LastName><MiddleName>L</MiddleName><CustomerKey>11001</CustomerKey>
  25. 25. <BirthDate>1965-05-14T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>S</MaritalStatus><City>Seaford</City><StateCode>VIC</StateCode><StateName>Victoria</StateName><CountryCode>AU</CountryCode><TerritoryCountry>Australia</TerritoryCountry><Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></customer><customer><FirstName>Ruben</FirstName><LastName>Torres</LastName><CustomerKey>11002</CustomerKey><BirthDate>1965-08-12T00:00:00</BirthDate><Gender>M</Gender><MaritalStatus>M</MaritalStatus><City>Hobart</City><StateCode>TAS</StateCode><StateName>Tasmania</StateName><CountryCode>AU</CountryCode><TerritoryCountry>Australia</TerritoryCountry><Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></customer><customer><FirstName>Christy</FirstName><LastName>Zhu</LastName><CustomerKey>11003</CustomerKey><BirthDate>1968-02-15T00:00:00</BirthDate><Gender>F</Gender><MaritalStatus>S</MaritalStatus><City>North Ryde</City><StateCode>NSW</StateCode><StateName>New South Wales</StateName><CountryCode>AU</CountryCode><TerritoryCountry>Australia</TerritoryCountry><Region>Australia</Region><TerritoryGroup>Pacific</TerritoryGroup></customer>RESULTS (ABRIDGED)/* displays null value instead of omitting it from the results*/select c.FirstName, c.LastName, c.Gender,CONVERT(DATE,c.BirthDate)as DOB, c.Title,
  26. 26. c.TotalChildren, s.ProductKey, s.Freight, s.TaxAmt, s.SalesOrderNumber,s.UnitPrice, s.ExtendedAmount, s.UnitPriceDiscountPct, s.DiscountAmount,s.TotalProductCost, s.UnitPrice, s.UnitPriceDiscountPctfrom dbo.FactInternetSales sinnerjoindbo.DimCustomer cons.CustomerKey = c.CustomerKeyORDERBY C.FirstNameFORXMLRAW(SALES),ELEMENTSXSINIL<SALESxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><FirstName>Aaron</FirstName><LastName>Collins</LastName><Gender>M</Gender><DOB>1960-09-24</DOB><Titlexsi:nil="true" /><TotalChildren>1</TotalChildren><ProductKey>310</ProductKey><Freight>89.4568</Freight><TaxAmt>286.2616</TaxAmt><SalesOrderNumber>SO43821</SalesOrderNumber><UnitPrice>3578.2700</UnitPrice><ExtendedAmount>3578.2700</ExtendedAmount><UnitPriceDiscountPct>0.000000000000000e+000</UnitPriceDiscountPct><DiscountAmount>0.000000000000000e+000</DiscountAmount><TotalProductCost>2171.2942</TotalProductCost></SALES><SALESxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><FirstName>Aaron</FirstName><LastName>Li</LastName><Gender>M</Gender><DOB>1979-04-19</DOB><Titlexsi:nil="true" /><TotalChildren>0</TotalChildren><ProductKey>325</ProductKey><Freight>19.5748</Freight><TaxAmt>62.6392</TaxAmt><SalesOrderNumber>SO48636</SalesOrderNumber><UnitPrice>782.9900</UnitPrice><ExtendedAmount>782.9900</ExtendedAmount><UnitPriceDiscountPct>0.000000000000000e+000</UnitPriceDiscountPct><DiscountAmount>0.000000000000000e+000</DiscountAmount><TotalProductCost>486.7066</TotalProductCost></SALES>RESULTS (ABRIDGED)select c.FirstName, c.LastName, c.Gender,CONVERT(DATE,c.BirthDate)as DOB, c.Title,c.TotalChildren, s.ProductKey, s.Freight, s.TaxAmt, s.SalesOrderNumber,s.UnitPrice, s.ExtendedAmount, s.UnitPriceDiscountPct, s.DiscountAmount,s.TotalProductCostfrom dbo.FactInternetSales sinnerjoindbo.DimCustomer cons.CustomerKey = c.CustomerKeyORDERBY C.FirstName
  27. 27. FORXMLRAW(SALES),ELEMENTSXSINIL,ROOT(REPORT)<REPORTxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SALES><FirstName>Aaron</FirstName><LastName>Collins</LastName><Gender>M</Gender><DOB>1960-09-24</DOB><Titlexsi:nil="true" /><TotalChildren>1</TotalChildren><ProductKey>310</ProductKey><Freight>89.4568</Freight><TaxAmt>286.2616</TaxAmt><SalesOrderNumber>SO43821</SalesOrderNumber><UnitPrice>3578.2700</UnitPrice><ExtendedAmount>3578.2700</ExtendedAmount><UnitPriceDiscountPct>0.000000000000000e+000</UnitPriceDiscountPct><DiscountAmount>0.000000000000000e+000</DiscountAmount><TotalProductCost>2171.2942</TotalProductCost></SALES><SALES><FirstName>Aaron</FirstName><LastName>Li</LastName><Gender>M</Gender><DOB>1979-04-19</DOB><Titlexsi:nil="true" /><TotalChildren>0</TotalChildren><ProductKey>325</ProductKey><Freight>19.5748</Freight><TaxAmt>62.6392</TaxAmt><SalesOrderNumber>SO48636</SalesOrderNumber><UnitPrice>782.9900</UnitPrice><ExtendedAmount>782.9900</ExtendedAmount><UnitPriceDiscountPct>0.000000000000000e+000</UnitPriceDiscountPct><DiscountAmount>0.000000000000000e+000</DiscountAmount><TotalProductCost>486.7066</TotalProductCost></SALES></REPORT>RESULTS (ABRIDGED)
  28. 28. ORACLE 11GDevelopment ToolsDatabase Platform: ORACLE 11GApplications: Oracle SQL Developer
  29. 29. SQL>desc studentName Null? Type----------------------------------------- -------- -------------------STUDENT_ID NOT NULL NUMBER(8)SALUTATION VARCHAR2(5)FIRST_NAME VARCHAR2(25)LAST_NAME NOT NULL VARCHAR2(25)STREET_ADDRESS VARCHAR2(50)ZIP NOT NULL VARCHAR2(5)PHONE VARCHAR2(15)EMPLOYER VARCHAR2(50)REGISTRATION_DATE NOT NULL DATECREATED_BY NOT NULL VARCHAR2(30)CREATED_DATE NOT NULL DATEMODIFIED_BY NOT NULL VARCHAR2(30)MODIFIED_DATE NOT NULL DATESELECT XMLELEMENT("NAME", FIRST_NAME), XMLELEMENT("STUDENT_ID", STUDENT_ID),XMLELEMENT("LAST_NAME", LAST_NAME)FROM STUDENTXMLELEMENT("NAME",FIRST_NAME) XMLELEMENT("STUDENT_ID",STUDENT_ID)XMLELEMENT("LAST_NAME",LAST_NAME)-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --------------------------------------------------------------------------------<NAME>Fred</NAME><STUDENT_ID>102</STUDENT_ID><LAST_NAME>Crocitto</LAST_NAME><NAME>J.</NAME><STUDENT_ID>103</STUDENT_ID><LAST_NAME>Landry</LAST_NAME><NAME>Laetia</NAME><STUDENT_ID>104</STUDENT_ID><LAST_NAME>Enison</LAST_NAME><NAME>Angel</NAME><STUDENT_ID>105</STUDENT_ID><LAST_NAME>Moskowitz</LAST_NAME>SELECT XMLELEMENT("STUDENT", xmlattributes(S.STUDENT_ID AS "STUDENT_ID"),XMLFOREST(S.FIRST_NAME ||,||S.LAST_NAME AS "STUDENT_NAME"),XMLFOREST(S.STREET_ADDRESS AS "ADDRESS"))FROM STUDENT SXMLELEMENT("STUDENT",XMLATTRIBUTES(S.STUDENT_IDAS"STUDENT_ID"),XMLFOREST(S.FIRST_NAME||,||S.LAST_NAMEAS"STUDENT_NAME"),XMLFOREST(S.STREET_ADDRESSAS"ADDRESS"))-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  30. 30. <STUDENT STUDENT_ID="102"><STUDENT_NAME>Fred,Crocitto</STUDENT_NAME><ADDRESS>101-09 120thSt.</ADDRESS></STUDENT><STUDENT STUDENT_ID="103"><STUDENT_NAME>J.,Landry</STUDENT_NAME><ADDRESS>7435 Boulevard East#45</ADDRESS></STUDENT><STUDENT STUDENT_ID="104"><STUDENT_NAME>Laetia,Enison</STUDENT_NAME><ADDRESS>144-61 87thAve</ADDRESS></STUDENT><STUDENT STUDENT_ID="105"><STUDENT_NAME>Angel,Moskowitz</STUDENT_NAME><ADDRESS>320 JohnSt.</ADDRESS></STUDENT><STUDENT STUDENT_ID="106"><STUDENT_NAME>Judith,Olvsade</STUDENT_NAME><ADDRESS>29 ElmwoodAve.</ADDRESS></STUDENT><STUDENT STUDENT_ID="107"><STUDENT_NAME>Catherine,Mierzwa</STUDENT_NAME><ADDRESS>22-70 41stSt.</ADDRESS></STUDENT><STUDENT STUDENT_ID="108"><STUDENT_NAME>Judy,Sethi</STUDENT_NAME><ADDRESS>Stratton Hall</ADDRESS></STUDENT>Result AbbreviatedSQL> create table studentxml(student_id number , dtsys.xmltype);Table created.SQL> insert into studentxmlvalues(999,2 sys.xmltype.createxml(3 <?xml version = "1.0"?>4 <student>5 <name> Michael Smith Jackson</name>6 <student_type> Graduate </student_type>7 <program> Information systems-Web Applications </program>8 </student>))9 /1 row created.SQL> insert into studentxmlvalues(566,2 sys.xmltype.createxml(3 <?xml version = "1.0"?>4 <student>5 <name> Young Andrew Jackson</name>6 <student_type> Graduate </student_type>7 <program> Information systems-Database Systems </program>8 </student>))9 /1 row created.SQL> set long 8900SQL> select * from studentxml;
  31. 31. STUDENT_ID----------DT-----------------------------------------------------------------999<?xml version = "1.0"?><student><name> Michael Smith Jackson</name><student_type> Graduate </student_type><program> Information systems-Web Applications </program></student>566STUDENT_ID----------DT-----------------------------------------------------------------<?xml version = "1.0"?><student><name> Young Andrew Jackson</name><student_type> Graduate </student_type><program> Information systems-Database Systems </program></student>SQL> select EXTRACTVALUE(S.dt,//student/name) FROM studentxml S;EXTRACTVALUE(S.DT,//STUDENT/NAME)--------------------------------------------------------------------------------Michael Smith JacksonYoung Andrew JacksonSQL> create table employeex2 (ID number primary key,3 employee XMLTYPE NOT NULL4 );Table created.SQL>descemployeexName Null? Type----------------------------------------- -------- ----------------
  32. 32. ID NOT NULL NUMBEREMPLOYEE NOT NULL PUBLIC.XMLTYPESQL> insert into employeex2 VALUES(908997,xmltype(<?xml version="1.0" standalone ="no"?>3 <employee>4 <emp>5 <name> Richard Blue William</name>6 </emp>7 </employee>));1 row created.SQL> insert into employeex2 VALUES(877997,xmltype(<?xml version="1.0" standalone ="no"?>3 <employee>4 <emp>5 <name>Rubby Diane Clay </name>6 </emp>7 </employee>));1 row created.SQL> select * from employeex2 /ID----------EMPLOYEE---------------------------------------------------------908997<?xml version="1.0" standalone ="no"?><employee><emp><name> Richard Blue William</name></emp></employee>877997ID----------EMPLOYEE
  33. 33. ---------------------------------------------------------<?xml version="1.0" standalone ="no"?><employee><emp><name>Rubby Diane Clay </name></emp></employee>SQL> update employeex2 set employee = updatexml(employee,/employee/emp/name/text(),Rubby Washington)3 where ID = 877997;1 row updated.ID----------EMPLOYEE--------------------------------------------------------------------------------877997<?xml version="1.0" standalone=no?><employee><emp><name>Rubby Washington</name></emp></employee>SQL> insert into employeex2 VALUES(437421,xmltype(<?xml version="1.0" standalone ="yes"?>3 <employee>4 <emp>5 <name> Liz Benson </name>6 </emp>7 </employee>));1 row created.SQL> select * from employeex where id = 437421;ID----------EMPLOYEE--------------------------------------------------------------------------------437421
  34. 34. <?xml version="1.0" standalone ="yes"?><employee><emp><name> Liz Benson </name></emp></employee>SQL> delete employeex2 where id = 908997;1 row deleted.SQL> select * from employeex;ID----------EMPLOYEE--------------------------------------------------------------------------------877997<?xml version="1.0" standalone=no?><employee><emp><name>Rubby Washington</name></emp></employee>437421<?xml version="1.0" standalone ="yes"?><employee><emp><name> Liz Benson </name>ID----------EMPLOYEE--------------------------------------------------------------------------------</emp></employee>

×