MICROSOFT SQL SERVER & ORACLE 11G XML
By
Sunny Okoro
ContentsMICROSOFT SQL SERVER.............................................................................................................................2
ORACLE 11G..............................................................................................................................................33
MICROSOFT SQL SERVER
Development Tools
Database Platform: Microsoft SQL Server 2008R2
/*inserting data from query into a table from product.xml*/
Use AdventureWorks Go
create table prodxml(productnumber xml ,quantity xml, price xml)
insert into prodxml(productnumber,quantity, price) Select g.value('@PRODNUMBER', 'nvarchar(10)') as Productnumber, g.value('@quantity', 'nvarchar(10)') as Quantity, g.value('@price', 'nvarchar(20)') as Price FROM( select cast (bulkcolumn as xml)as data from openrowset(bulk 'c:\temp\product.xml', single_blob) as g)h Cross apply data.nodes('/PRODUCT/PRODUCT') c(g)
Select * from prodxml
/*Using Value() method to reterive scalar value from an XML document */
declare @s xml select @s = '<Student StudentID = "0989" StudentSNN="409569090" />' select @s.value('(Student/@StudentID)[1]', 'CHAR(8)') as STUDENTID, @s.value('(Student/@StudentSNN)[1]','char(12)') as STUDENTSNN
STUDENTID
STUDENTSNN
989 409569090
/* Using the nodes method to return row set */
declare @pid xml select @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_number from @pid.nodes('/PRODUCT/PRODNUMBER')b(a)
product_number190180170160150140120
/* Joining XML nodews with relational tables */
Use AdventureWorksDWGo
CREATE TABLE CUSTOMER1(RECORD_ID INT IDENTITY PRIMARY KEY, CUSTOMER_ID INT, FIRST_NAME NVARCHAR(50), MIDDLE_NAME NVARCHAR(50), LAST_NAME NVARCHAR(50) ); GO
CREATE TABLE CUSTOMER2(RECORD_ID INT, CUSTOMER_DATA XML);
Alter table customer1 add geographykey char(20);
Alter table customer1 add city nvarchar(30);
Alter table customer1 add statename nvarchar(50);
Alter table customer1 add statecode nvarchar(3);
Alter table customer1 add countycode nvarchar(3);
Alter table customer1 add POSTALCODE nvarchar(15);
Update customer1 set
INSERT INTO CUSTOMER1(CUSTOMER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME)
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.CUSTOMER1 set geographykey = (select GeographyKey from dbo.DimCustomer where CustomerKey = 11000) where customer_id = 11000
update dbo.CUSTOMER1
set city = 'Rockhampton' where customer_id = 11000; go update dbo.CUSTOMER1 set statename = 'Queensland' where customer_id = 11000; go update dbo.CUSTOMER1 set statecode = 'QLD' where customer_id = 11000; go update dbo.CUSTOMER1 set countycode = 'AU' where customer_id = 11000; go update dbo.CUSTOMER1 set postalcode = '4700' where customer_id = 11000; go
update dbo.CUSTOMER1 set geographykey = (select GeographyKey from dbo.DimCustomer where CustomerKey = 11062) where customer_id = 11062; go
update dbo.CUSTOMER1 set city = 'Portland' where customer_id = 11062; go update dbo.CUSTOMER1 set statename = 'Oregon' where customer_id = 11062; go update dbo.CUSTOMER1 set statecode = 'OR' where customer_id = 11062; go
update dbo.CUSTOMER1 set countycode = 'US' where customer_id = 11062; go update dbo.CUSTOMER1 set postalcode = '97205' where customer_id = 11062; go
update dbo.CUSTOMER1 set geographykey = (select GeographyKey from dbo.DimCustomer where CustomerKey = 11000) where customer_id = 11010
update dbo.CUSTOMER1 set city = 'East Brisbane' where customer_id = 11010; go update dbo.CUSTOMER1 set statename = 'Queensland' where customer_id = 11010; go update dbo.CUSTOMER1 set statecode = 'QLD' where customer_id = 11010; go update dbo.CUSTOMER1 set countycode = 'AU' where customer_id = 11010; go update dbo.CUSTOMER1 set postalcode = '4169' where customer_id = 11010; go
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 >'
use AdventureWorksDWgo
select customer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,customer.BirthDate, customer.Gender, customer.MaritalStatus from dbo.DimCustomer customer order by NEWID() for xml auto;
Results
<customer FirstName="Ian" LastName="Watson" MiddleName="G" CustomerKey="26398" BirthDate="1945-06-10T00:00:00" Gender="M" MaritalStatus="M" /><customer FirstName="Jordan" LastName="Green" MiddleName="L" CustomerKey="27915" BirthDate="1974-04-25T00:00:00" Gender="F" MaritalStatus="S" /><customer FirstName="Gregory" LastName="Yuan" CustomerKey="21822" BirthDate="1957-02-26T00:00:00" Gender="M" MaritalStatus="S" /><customer FirstName="Jasmine" LastName="Smith" CustomerKey="28891" BirthDate="1945-11-01T00:00:00" Gender="F" MaritalStatus="S" /><customer FirstName="Shane" LastName="Sai" MiddleName="R" CustomerKey="29374" BirthDate="1965-05-21T00:00:00" Gender="M" MaritalStatus="M" />
<customer FirstName="Cameron" LastName="Patterson" MiddleName="M" CustomerKey="25790" BirthDate="1953-09-10T00:00:00" Gender="M" MaritalStatus="M" /><customer FirstName="Bradley" LastName="Rai" CustomerKey="19100" BirthDate="1971-06-01T00:00:00" Gender="M" MaritalStatus="M" /><customer FirstName="Isaiah" LastName="Roberts" MiddleName="M" CustomerKey="27211" BirthDate="1955-10-12T00:00:00" Gender="M" MaritalStatus="M" /><customer FirstName="Stacy" LastName="Serrano" CustomerKey="24613" BirthDate="1970-09-23T00:00:00" Gender="F" MaritalStatus="M" /><customer FirstName="Eugene" LastName="Zhao" CustomerKey="12328" BirthDate="1950-03-18T00:00:00" Gender="M" MaritalStatus="S" /><customer FirstName="Noah" LastName="Nelson" CustomerKey="16835" BirthDate="1933-10-14T00:00:00" Gender="M" MaritalStatus="M" />
RESULTS (ABRIDGED)
use AdventureWorksDWgo
select 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 from dbo.DimCustomer customer inner join dbo.DimGeography Geography on customer.GeographyKey = Geography.GeographyKey order by NEWID() for xml auto;
<customer FirstName="Kellie" LastName="Dominguez" MiddleName="E" CustomerKey="17244" BirthDate="1972-02-25T00:00:00" Gender="F" MaritalStatus="M"> <Geography City="Findon" StateCode="SA" StateName="South Australia" CountryCode="AU" /></customer><customer FirstName="Hector" LastName="Ruiz" CustomerKey="27592" BirthDate="1967-11-27T00:00:00" Gender="M" MaritalStatus="S"> <Geography City="Newcastle" StateCode="NSW" StateName="New South Wales" CountryCode="AU" /></customer>
<customer FirstName="Joseph" LastName="Taylor" MiddleName="T" CustomerKey="12289" BirthDate="1968-03-23T00:00:00" Gender="M" MaritalStatus="S"> <Geography City="Stoke-on-Trent" StateCode="ENG" StateName="England" CountryCode="GB" /></customer><customer FirstName="Theodore" LastName="Moreno" MiddleName="C" CustomerKey="20872" BirthDate="1968-02-21T00:00:00" Gender="M" MaritalStatus="S"> <Geography City="Gateshead" StateCode="ENG" StateName="England" CountryCode="GB" /></customer><customer FirstName="Roger" LastName="Sharma" MiddleName="L" CustomerKey="19454" BirthDate="1967-08-17T00:00:00" Gender="M" MaritalStatus="M"> <Geography City="Neunkirchen" StateCode="SL" StateName="Saarland" CountryCode="DE" />
RESULTS (ABRIDGED)
use AdventureWorksDWgo
select 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 TerritoryGroup from dbo.DimCustomer customer inner join dbo.DimGeography Geography on customer.GeographyKey = Geography.GeographyKey inner join dbo.DimSalesTerritory Territory on Territory.salesterritorykey = Geography.salesterritorykey order by NEWID() for xml auto;
<customer FirstName="Wayne" LastName="Nara" MiddleName="C" CustomerKey="23869" BirthDate="1970-03-15T00:00:00" Gender="M" MaritalStatus="M">
<Geography City="Ballard" StateCode="WA" StateName="Washington" CountryCode="US"> <Territory TerritoryCountry="United States" Region="Northwest" TerritoryGroup="North America" /> </Geography></customer><customer FirstName="Bailey" LastName="Allen" MiddleName="F" CustomerKey="27218" BirthDate="1957-11-07T00:00:00" Gender="F" MaritalStatus="M"> <Geography City="Santa Monica" StateCode="CA" StateName="California" CountryCode="US"> <Territory TerritoryCountry="United States" Region="Southwest" TerritoryGroup="North America" /> </Geography></customer><customer FirstName="Garrett" LastName="Sanchez" MiddleName="E" CustomerKey="15885" BirthDate="1946-05-18T00:00:00" Gender="M" MaritalStatus="S"> <Geography City="Sedro Woolley" StateCode="WA" StateName="Washington" CountryCode="US"> <Territory TerritoryCountry="United States" Region="Northwest" TerritoryGroup="North America" /> </Geography></customer><customer FirstName="Jackson" LastName="Alexander" CustomerKey="20876" BirthDate="1968-04-27T00:00:00" Gender="M" MaritalStatus="S"> <Geography City="Darmstadt" StateCode="HE" StateName="Hessen" CountryCode="DE"> <Territory TerritoryCountry="Germany" Region="Germany" TerritoryGroup="Europe" /> </Geography></customer><customer FirstName="Katherine" LastName="Allen" CustomerKey="17457" BirthDate="1954-03-27T00:00:00" Gender="F" MaritalStatus="M"> <Geography City="Burien" StateCode="WA" StateName="Washington" CountryCode="US"> <Territory TerritoryCountry="United States" Region="Northwest" TerritoryGroup="North America" /> </Geography></customer>
RESULTS (ABRIDGED)
use AdventureWorksDW
go
select 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 TerritoryGroup from dbo.DimCustomer customer inner join dbo.DimGeography Geography on customer.GeographyKey = Geography.GeographyKey inner join dbo.DimSalesTerritory Territory on Territory.salesterritorykey = Geography.salesterritorykey for 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="New South 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="New South Wales" CountryCode="AU"> <Territory TerritoryCountry="Australia" Region="Australia" TerritoryGroup="Pacific" /> </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)
use AdventureWorksDWgo
select 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 TerritoryGroup from dbo.DimCustomer customer inner join dbo.DimGeography Geography on customer.GeographyKey = Geography.GeographyKey inner join dbo.DimSalesTerritory Territory on Territory.salesterritorykey = Geography.salesterritorykey for xml RAW;
<row FirstName="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" /><row FirstName="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" /><row FirstName="Christy" LastName="Zhu" CustomerKey="11003" BirthDate="1968-02-15T00:00:00" Gender="F" MaritalStatus="S" City="North Ryde" StateCode="NSW" StateName="New South Wales" CountryCode="AU" TerritoryCountry="Australia" Region="Australia" TerritoryGroup="Pacific" /><row FirstName="Elizabeth" LastName="Johnson" CustomerKey="11004" BirthDate="1968-08-08T00:00:00" Gender="F" MaritalStatus="S" City="Wollongong" StateCode="NSW" StateName="New South Wales" CountryCode="AU" TerritoryCountry="Australia" Region="Australia" TerritoryGroup="Pacific" /><row FirstName="Julio" LastName="Ruiz" CustomerKey="11005" BirthDate="1965-08-05T00:00:00" Gender="M" MaritalStatus="S" City="East Brisbane" StateCode="QLD" StateName="Queensland" CountryCode="AU" TerritoryCountry="Australia" Region="Australia" TerritoryGroup="Pacific" /><row FirstName="Janet" LastName="Alvarez" MiddleName="G" CustomerKey="11006" BirthDate="1965-12-06T00:00:00" Gender="F" MaritalStatus="S" City="Matraville" StateCode="NSW" StateName="New South Wales" CountryCode="AU" TerritoryCountry="Australia" Region="Australia" TerritoryGroup="Pacific" /><row FirstName="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" /><row FirstName="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" /><row FirstName="Shannon" LastName="Carlson" MiddleName="C" CustomerKey="11009" BirthDate="1964-04-01T00:00:00" Gender="M" MaritalStatus="S" City="Hervey Bay" StateCode="QLD" StateName="Queensland" CountryCode="AU" TerritoryCountry="Australia" Region="Australia" TerritoryGroup="Pacific" /><row FirstName="Jacquelyn" LastName="Suarez" MiddleName="C" CustomerKey="11010" BirthDate="1964-02-06T00:00:00" Gender="F" MaritalStatus="S" City="East Brisbane" StateCode="QLD"
RESULTS (ABRIDGED)
use AdventureWorksDWgo
select 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 TerritoryGroup from dbo.DimCustomer customer inner join dbo.DimGeography Geography on customer.GeographyKey = Geography.GeographyKey inner join dbo.DimSalesTerritory Territory on Territory.salesterritorykey = Geography.salesterritorykey where customer.FirstName = 'Eugene' for xml RAW('Customer'), Root('Customer');
<Customer> <Customer FirstName="Eugene" LastName="Ma" MiddleName="A" CustomerKey="24374" BirthDate="1965-10-13T00:00:00" Gender="M" MaritalStatus="S" City="Silverwater" StateCode="NSW" StateName="New South Wales" CountryCode="AU" TerritoryCountry="Australia" Region="Australia" TerritoryGroup="Pacific" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="Eugene" LastName="Liang" CustomerKey="13972" BirthDate="1965-04-02T00:00:00" Gender="M" MaritalStatus="S" City="Perth" StateCode="SA" StateName="South Australia" CountryCode="AU" TerritoryCountry="Australia" Region="Australia" TerritoryGroup="Pacific" /> <Customer FirstName="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" /> <Customer FirstName="Eugene" LastName="Li" MiddleName="A" CustomerKey="15283" BirthDate="1972-11-22T00:00:00" Gender="M" MaritalStatus="S" City="Cliffside" StateCode="BC" StateName="British Columbia" CountryCode="CA" TerritoryCountry="Canada" Region="Canada" TerritoryGroup="North America" /> <Customer FirstName="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" />
<Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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" /> <Customer FirstName="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>
use AdventureWorksDWgo
select 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 TerritoryGroup from dbo.DimCustomer customer inner join dbo.DimGeography Geography on customer.GeographyKey = Geography.GeographyKey inner join dbo.DimSalesTerritory Territory on Territory.salesterritorykey = Geography.salesterritorykey where customer.FirstName = 'Eugene' for 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>
<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>
select customer.CustomerKey as[@custno],customer.FirstName as [Customer/customer] from dbo.DimCustomer as customer where customer.FirstName = 'Eugene' for 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 AdventureWorksDWgo
select 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 TerritoryGroup from dbo.DimCustomer customer inner join dbo.DimGeography Geography
on customer.GeographyKey = Geography.GeographyKey inner join dbo.DimSalesTerritory Territory on Territory.salesterritorykey = Geography.salesterritorykey for 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>
<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 AdventureWorksDWgo
select 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 )t inner join dbo.DimGeography Geography on Geography.SalesTerritoryKey = t.[@Territory-key] inner join
dbo.DimCustomer customer on customer.GeographyKey = Geography.GeographyKeyFOR XML PATH('CUSTOMER'), ROOT('CUSTOMER')
CUSTOMER> <CUSTOMER CUST_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" /> <CUSTOMER CUST_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" /> <CUSTOMER CUST_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" /> <CUSTOMER CUST_ID="11003" FIRST_NAME="Christy" LAST_NAME="Zhu" DOB="1968-02-15" GENDER="F" Marital_status="S" CITY="North
Ryde" State-Code="NSW" State="New South Wales" Country-Code="AU" />
<CUSTOMER CUST_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)
use AdventureWorksDWgo
select 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 TerritoryGroup from dbo.DimCustomer customer inner join dbo.DimGeography Geography on customer.GeographyKey = Geography.GeographyKey inner join dbo.DimSalesTerritory Territory on Territory.salesterritorykey = Geography.salesterritorykey where customer.FirstName = 'Eugene' for xml RAW('customer'),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> <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,
c.TotalChildren, s.ProductKey, s.Freight, s.TaxAmt, s.SalesOrderNumber,s.UnitPrice, s.ExtendedAmount, s.UnitPriceDiscountPct, s.DiscountAmount,s.TotalProductCost, s.UnitPrice, s.UnitPriceDiscountPct from dbo.FactInternetSales s inner join dbo.DimCustomer c on s.CustomerKey = c.CustomerKey ORDER BY C.FirstName FOR XML RAW('SALES'), ELEMENTS XSINIL
<SALES xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <FirstName>Aaron</FirstName> <LastName>Collins</LastName> <Gender>M</Gender> <DOB>1960-09-24</DOB> <Title xsi: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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <FirstName>Aaron</FirstName> <LastName>Li</LastName> <Gender>M</Gender> <DOB>1979-04-19</DOB> <Title xsi: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.TotalProductCost from dbo.FactInternetSales s inner join dbo.DimCustomer c on s.CustomerKey = c.CustomerKey ORDER BY C.FirstName
FOR XML RAW('SALES'), ELEMENTS XSINIL, ROOT('REPORT')
<REPORT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SALES> <FirstName>Aaron</FirstName> <LastName>Collins</LastName> <Gender>M</Gender> <DOB>1960-09-24</DOB> <Title xsi: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> <Title xsi: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)
ORACLE 11G
Development Tools
Database Platform: ORACLE 11G
Applications: Oracle SQL Developer
SQL> desc student Name 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 DATE CREATED_BY NOT NULL VARCHAR2(30) CREATED_DATE NOT NULL DATE MODIFIED_BY NOT NULL VARCHAR2(30) MODIFIED_DATE NOT NULL DATE
SELECT XMLELEMENT("NAME", FIRST_NAME), XMLELEMENT("STUDENT_ID", STUDENT_ID), XMLELEMENT("LAST_NAME", LAST_NAME) FROM STUDENT
XMLELEMENT("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 S
XMLELEMENT("STUDENT",XMLATTRIBUTES(S.STUDENT_IDAS"STUDENT_ID"),XMLFOREST(S.FIRST_NAME||','||S.LAST_NAMEAS"STUDENT_NAME"),XMLFOREST(S.STREET_ADDRESSAS"ADDRESS")) -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<STUDENT STUDENT_ID="102"><STUDENT_NAME>Fred,Crocitto</STUDENT_NAME><ADDRESS>101-09 120th St.</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 87th Ave</ADDRESS></STUDENT> <STUDENT STUDENT_ID="105"><STUDENT_NAME>Angel,Moskowitz</STUDENT_NAME><ADDRESS>320 John St.</ADDRESS></STUDENT> <STUDENT STUDENT_ID="106"><STUDENT_NAME>Judith,Olvsade</STUDENT_NAME><ADDRESS>29 Elmwood Ave.</ADDRESS></STUDENT> <STUDENT STUDENT_ID="107"><STUDENT_NAME>Catherine,Mierzwa</STUDENT_NAME><ADDRESS>22-70 41st St.</ADDRESS></STUDENT> <STUDENT STUDENT_ID="108"><STUDENT_NAME>Judy,Sethi</STUDENT_NAME><ADDRESS>Stratton Hall</ADDRESS></STUDENT>
Result Abbreviated
SQL> create table studentxml(student_id number , dt sys.xmltype);Table created.
SQL> insert into studentxml values(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 studentxml values(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;
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>
566
STUDENT_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 Jackson Young Andrew Jackson
SQL> create table employeex 2 (ID number primary key, 3 employee XMLTYPE NOT NULL 4 );
Table created.
SQL> desc employeex Name Null? Type ----------------------------------------- -------- ----------------
ID NOT NULL NUMBER EMPLOYEE NOT NULL PUBLIC.XMLTYPE
SQL> insert into employeex 2 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 employeex 2 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 employeex 2 /
ID----------EMPLOYEE---------------------------------------------------------
908997<?xml version="1.0" standalone ="no"?> <employee> <emp> <name> Richard Blue William</name> </emp></employee>
877997
ID----------EMPLOYEE---------------------------------------------------------
<?xml version="1.0" standalone ="no"?> <employee> <emp> <name> Rubby Diane Clay </name> </emp></employee>
SQL> update employeex 2 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 employeex 2 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<?xml version="1.0" standalone ="yes"?> <employee> <emp> <name> Liz Benson </name> </emp></employee>
SQL> delete employeex 2 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>