SlideShare a Scribd company logo
MICROSOFT SQL SERVER &
ORACLE 11G XML
By
Sunny Okoro
Contents
MICROSOFT SQL SERVER...............................................................................................................................2
ORACLE 11G................................................................................................................................................11
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:tempproduct.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_number
190
180
170
160
150
140
120
/* Joining XML nodews with relational tables */
Use AdventureWorksDW
Go
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
addgeographykey char(20);
Alter table customer1
add city nvarchar(30);
Alter table customer1
addstatenamenvarchar(50);
Alter table customer1
addstatecodenvarchar(3);
Alter table customer1
addcountycodenvarchar(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
setgeographykey = (select GeographyKey from dbo.DimCustomer where CustomerKey =
11000)
wherecustomer_id = 11000
update dbo.CUSTOMER1
set city = 'Rockhampton'
wherecustomer_id = 11000;
go
update dbo.CUSTOMER1
setstatename = 'Queensland'
wherecustomer_id = 11000;
go
update dbo.CUSTOMER1
setstatecode = 'QLD'
wherecustomer_id = 11000;
go
update dbo.CUSTOMER1
setcountycode = 'AU'
wherecustomer_id = 11000;
go
update dbo.CUSTOMER1
setpostalcode = '4700'
wherecustomer_id = 11000;
go
update dbo.CUSTOMER1
setgeographykey = (select GeographyKey from dbo.DimCustomer where CustomerKey =
11062)
wherecustomer_id = 11062;
go
update dbo.CUSTOMER1
set city = 'Portland'
wherecustomer_id = 11062;
go
update dbo.CUSTOMER1
setstatename = 'Oregon'
wherecustomer_id = 11062;
go
update dbo.CUSTOMER1
setstatecode = 'OR'
wherecustomer_id = 11062;
go
update dbo.CUSTOMER1
setcountycode = 'US'
wherecustomer_id = 11062;
go
update dbo.CUSTOMER1
setpostalcode = '97205'
wherecustomer_id = 11062;
go
update dbo.CUSTOMER1
setgeographykey = (select GeographyKey from dbo.DimCustomer where CustomerKey =
11000)
wherecustomer_id = 11010
update dbo.CUSTOMER1
set city = 'East Brisbane'
wherecustomer_id = 11010;
go
update dbo.CUSTOMER1
setstatename = 'Queensland'
wherecustomer_id = 11010;
go
update dbo.CUSTOMER1
setstatecode = 'QLD'
wherecustomer_id = 11010;
go
update dbo.CUSTOMER1
setcountycode = 'AU'
wherecustomer_id = 11010;
go
update dbo.CUSTOMER1
setpostalcode = '4169'
wherecustomer_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 >'
useAdventureWorksDW
go
selectcustomer.FirstName, customer.LastName, customer.MiddleName, customer.CustomerKey,
customer.BirthDate, customer.Gender, customer.MaritalStatus
fromdbo.DimCustomer customer
order by NEWID()
for xml auto;
Results
<customerFirstName="Ian"LastName="Watson"MiddleName="G"CustomerK
ey="26398"BirthDate="1945-06-
10T00:00:00"Gender="M"MaritalStatus="M" />
<customerFirstName="Jordan"LastName="Green"MiddleName="L"Custome
rKey="27915"BirthDate="1974-04-
25T00:00:00"Gender="F"MaritalStatus="S" />
<customerFirstName="Gregory"LastName="Yuan"CustomerKey="21822"Bi
rthDate="1957-02-26T00:00:00"Gender="M"MaritalStatus="S" />
<customerFirstName="Jasmine"LastName="Smith"CustomerKey="28891"B
irthDate="1945-11-01T00:00:00"Gender="F"MaritalStatus="S" />
<customerFirstName="Shane"LastName="Sai"MiddleName="R"CustomerKe
y="29374"BirthDate="1965-05-
21T00:00:00"Gender="M"MaritalStatus="M" />
<customerFirstName="Cameron"LastName="Patterson"MiddleName="M"Cu
stomerKey="25790"BirthDate="1953-09-
10T00:00:00"Gender="M"MaritalStatus="M" />
<customerFirstName="Bradley"LastName="Rai"CustomerKey="19100"Bir
thDate="1971-06-01T00:00:00"Gender="M"MaritalStatus="M" />
<customerFirstName="Isaiah"LastName="Roberts"MiddleName="M"Custo
merKey="27211"BirthDate="1955-10-
12T00:00:00"Gender="M"MaritalStatus="M" />
<customerFirstName="Stacy"LastName="Serrano"CustomerKey="24613"B
irthDate="1970-09-23T00:00:00"Gender="F"MaritalStatus="M" />
<customerFirstName="Eugene"LastName="Zhao"CustomerKey="12328"Bir
thDate="1950-03-18T00:00:00"Gender="M"MaritalStatus="S" />
<customerFirstName="Noah"LastName="Nelson"CustomerKey="16835"Bir
thDate="1933-10-14T00:00:00"Gender="M"MaritalStatus="M" />
RESULTS (ABRIDGED)
useAdventureWorksDW
go
selectcustomer.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
fromdbo.DimCustomer customer
inner join
dbo.DimGeography Geography
on
customer.GeographyKey = Geography.GeographyKey
order by NEWID()
for xml auto;
<customerFirstName="Kellie"LastName="Dominguez"MiddleName="E"Cus
tomerKey="17244"BirthDate="1972-02-
25T00:00:00"Gender="F"MaritalStatus="M">
<GeographyCity="Findon"StateCode="SA"StateName="South
Australia"CountryCode="AU" />
</customer>
<customerFirstName="Hector"LastName="Ruiz"CustomerKey="27592"Bir
thDate="1967-11-27T00:00:00"Gender="M"MaritalStatus="S">
<GeographyCity="Newcastle"StateCode="NSW"StateName="New South
Wales"CountryCode="AU" />
</customer>
<customerFirstName="Joseph"LastName="Taylor"MiddleName="T"Custom
erKey="12289"BirthDate="1968-03-
23T00:00:00"Gender="M"MaritalStatus="S">
<GeographyCity="Stoke-on-
Trent"StateCode="ENG"StateName="England"CountryCode="GB" />
</customer>
<customerFirstName="Theodore"LastName="Moreno"MiddleName="C"Cust
omerKey="20872"BirthDate="1968-02-
21T00:00:00"Gender="M"MaritalStatus="S">
<GeographyCity="Gateshead"StateCode="ENG"StateName="England"Coun
tryCode="GB" />
</customer>
<customerFirstName="Roger"LastName="Sharma"MiddleName="L"Custome
rKey="19454"BirthDate="1967-08-
17T00:00:00"Gender="M"MaritalStatus="M">
<GeographyCity="Neunkirchen"StateCode="SL"StateName="Saarland"Co
untryCode="DE" />
RESULTS (ABRIDGED)
useAdventureWorksDW
go
selectcustomer.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
fromdbo.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;
<customerFirstName="Wayne"LastName="Nara"MiddleName="C"CustomerK
ey="23869"BirthDate="1970-03-
15T00:00:00"Gender="M"MaritalStatus="M">
<GeographyCity="Ballard"StateCode="WA"StateName="Washington"Coun
tryCode="US">
<TerritoryTerritoryCountry="United
States"Region="Northwest"TerritoryGroup="North America" />
</Geography>
</customer>
<customerFirstName="Bailey"LastName="Allen"MiddleName="F"Custome
rKey="27218"BirthDate="1957-11-
07T00:00:00"Gender="F"MaritalStatus="M">
<GeographyCity="Santa
Monica"StateCode="CA"StateName="California"CountryCode="US">
<TerritoryTerritoryCountry="United
States"Region="Southwest"TerritoryGroup="North America" />
</Geography>
</customer>
<customerFirstName="Garrett"LastName="Sanchez"MiddleName="E"Cust
omerKey="15885"BirthDate="1946-05-
18T00:00:00"Gender="M"MaritalStatus="S">
<GeographyCity="Sedro
Woolley"StateCode="WA"StateName="Washington"CountryCode="US">
<TerritoryTerritoryCountry="United
States"Region="Northwest"TerritoryGroup="North America" />
</Geography>
</customer>
<customerFirstName="Jackson"LastName="Alexander"CustomerKey="208
76"BirthDate="1968-04-27T00:00:00"Gender="M"MaritalStatus="S">
<GeographyCity="Darmstadt"StateCode="HE"StateName="Hessen"Countr
yCode="DE">
<TerritoryTerritoryCountry="Germany"Region="Germany"TerritoryGro
up="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"Count
ryCode="US">
<TerritoryTerritoryCountry="United
States"Region="Northwest"TerritoryGroup="North America" />
</Geography>
</customer>
RESULTS (ABRIDGED)
useAdventureWorksDW
go
selectcustomer.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
fromdbo.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)
useAdventureWorksDW
go
selectcustomer.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
fromdbo.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;
<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"TerritoryCo
untry="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"TerritoryCou
ntry="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 South
Wales"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 South
Wales"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="East
Brisbane"StateCode="QLD"StateName="Queensland"CountryCode="AU"TerritoryCountry="Australia"Region="Australia"Territo
ryGroup="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 South
Wales"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"Territo
ryCountry="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"TerritoryCo
untry="Australia"Region="Australia"TerritoryGroup="Pacific" />
<rowFirstName="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"TerritoryGro
up="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)
useAdventureWorksDW
go
selectcustomer.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
fromdbo.DimCustomer customer
inner join
dbo.DimGeography Geography
on
customer.GeographyKey = Geography.GeographyKey
inner join
dbo.DimSalesTerritory Territory
on
Territory.salesterritorykey = Geography.salesterritorykey
wherecustomer.FirstName = 'Eugene'
for 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 South
Wales"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"CountryCo
de="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="South
Australia"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="British
Columbia"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" />
<CustomerFirstName="Eugene"LastName="Zeng"CustomerKey="24025"BirthDate="1960-01-
02T00:00:00"Gender="M"MaritalStatus="M"City="Hamburg"StateCode="HE"StateName="Hessen"CountryCode="DE"Te
rritoryCountry="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"Te
rritoryCountry="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"Te
rritoryCountry="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"T
erritoryCountry="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="D
E"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"Te
rritoryCountry="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"CountryC
ode="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"T
erritoryCountry="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"T
erritoryCountry="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"Ter
ritoryCountry="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="U
S"TerritoryCountry="United States"Region="Southwest"TerritoryGroup="North America" />
</Customer>
useAdventureWorksDW
go
selectcustomer.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
fromdbo.DimCustomer customer
inner join
dbo.DimGeography Geography
on
customer.GeographyKey = Geography.GeographyKey
inner join
dbo.DimSalesTerritory Territory
on
Territory.salesterritorykey = Geography.salesterritorykey
wherecustomer.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>
selectcustomer.CustomerKey as[@custno],
customer.FirstName as [Customer/customer]
fromdbo.DimCustomer as customer
wherecustomer.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 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, 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 AdventureWorksDW
go
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
innerjoin
dbo.DimGeography Geography
on
Geography.SalesTerritoryKey = t.[@Territory-key]
innerjoin
dbo.DimCustomer customer
on
customer.GeographyKey =Geography.GeographyKey
FORXMLPATH('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="North
Ryde"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)
useAdventureWorksDW
go
selectcustomer.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
fromdbo.DimCustomer customer
inner join
dbo.DimGeography Geography
on
customer.GeographyKey = Geography.GeographyKey
inner join
dbo.DimSalesTerritory Territory
on
Territory.salesterritorykey = Geography.salesterritorykey
wherecustomer.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
innerjoin
dbo.DimCustomer c
on
s.CustomerKey = c.CustomerKey
ORDERBY C.FirstName
FORXMLRAW('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.TotalProductCost
from dbo.FactInternetSales s
innerjoin
dbo.DimCustomer c
on
s.CustomerKey = c.CustomerKey
ORDERBY C.FirstName
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)
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"STU
DENT_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 , 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 8900
SQL> 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>descemployeex
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 Wash
ington')
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>

More Related Content

PPTX
Mongo db basic installation
PPTX
Typed? Dynamic? Both! Cross-platform DSLs in C#
PDF
Explaining cXML Messages - SiteSphere PunchOut Catalogs
PPTX
Indexing and Query Optimizer (Aaron Staple)
PDF
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
PPT
Fast querying indexing for performance (4)
PDF
Cassandra Summit 2015
KEY
Mongo db ecommerce
Mongo db basic installation
Typed? Dynamic? Both! Cross-platform DSLs in C#
Explaining cXML Messages - SiteSphere PunchOut Catalogs
Indexing and Query Optimizer (Aaron Staple)
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
Fast querying indexing for performance (4)
Cassandra Summit 2015
Mongo db ecommerce

What's hot (7)

PDF
MongoDB World 2016: Deciphering .explain() Output
PDF
Agile Database Development with JSON
DOC
Functions
PDF
Testdrevet javautvikling på objektorienterte skinner
PPS
MongoDB crud
PDF
How to write bad code in redux (ReactNext 2018)
PDF
Scaling MySQL Strategies for Developers
MongoDB World 2016: Deciphering .explain() Output
Agile Database Development with JSON
Functions
Testdrevet javautvikling på objektorienterte skinner
MongoDB crud
How to write bad code in redux (ReactNext 2018)
Scaling MySQL Strategies for Developers
Ad

Viewers also liked (20)

PPT
XML, XML Databases and MPEG-7
PPTX
Mpeg 7
PDF
PPTX
Evaluation: Question 3
PPTX
Monserrat mayen diaz
PPT
Demak
PDF
Flyer
PDF
Use credit union home loan basics 2 28 12
ODP
Dia del libro. Área de Inglés.
PDF
企劃書 取彗!
PPTX
Recommendations for bettermeans.com
PPSX
Aplicaciones del sistema operativo presentación
PPT
Anatómia i
PDF
BS's COMPANY PROFILE_VIETNAMESE
PPTX
Educational technology journal
PDF
Опрыскиватель ранцевый аккумуляторный Solo 416
PPTX
Lyserødlørdag 2012
DOC
Ctdl1
ODP
Generacion de ordenadores
XML, XML Databases and MPEG-7
Mpeg 7
Evaluation: Question 3
Monserrat mayen diaz
Demak
Flyer
Use credit union home loan basics 2 28 12
Dia del libro. Área de Inglés.
企劃書 取彗!
Recommendations for bettermeans.com
Aplicaciones del sistema operativo presentación
Anatómia i
BS's COMPANY PROFILE_VIETNAMESE
Educational technology journal
Опрыскиватель ранцевый аккумуляторный Solo 416
Lyserødlørdag 2012
Ctdl1
Generacion de ordenadores
Ad

Similar to Relational / XML DB -SQL Server & Oracle Database (20)

PPTX
Starting with JSON Path Expressions in Oracle 12.1.0.2
PDF
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
DOCX
DB 3 Sybase ASE 15 & MS SQL Server
PPTX
Neo4j Makes Graphs Easy: Nicole White
PPTX
AngularJS
PDF
Banking Database
PPTX
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
PDF
XML features in DB2 11 for z/OS
PPTX
Hacking Your Way To Better Security - DrupalCon Baltimore 2017
PPTX
Hacking Your Way to Better Security - ZendCon 2016
PDF
UKOUG Tech14 - Getting Started With JSON in the Database
PPTX
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
PDF
AngularJs
PPTX
Oracle Goldengate for Big Data - LendingClub Implementation
PDF
Getting started with apache solr
PPTX
ELEVATE Advanced Workshop
PDF
PPSX
JSON, A Splash of SODA, and a SQL Chaser: Real-World Use Cases for Autonomous...
DOCX
Hadoop sqoop2 server setup and application integration
PPTX
Oracle Database - JSON and the In-Memory Database
Starting with JSON Path Expressions in Oracle 12.1.0.2
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
DB 3 Sybase ASE 15 & MS SQL Server
Neo4j Makes Graphs Easy: Nicole White
AngularJS
Banking Database
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
XML features in DB2 11 for z/OS
Hacking Your Way To Better Security - DrupalCon Baltimore 2017
Hacking Your Way to Better Security - ZendCon 2016
UKOUG Tech14 - Getting Started With JSON in the Database
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
AngularJs
Oracle Goldengate for Big Data - LendingClub Implementation
Getting started with apache solr
ELEVATE Advanced Workshop
JSON, A Splash of SODA, and a SQL Chaser: Real-World Use Cases for Autonomous...
Hadoop sqoop2 server setup and application integration
Oracle Database - JSON and the In-Memory Database

More from Sunny U Okoro (20)

DOCX
SQL Server and SSAS
DOCX
BI Apps Reports 5 QlikSense Desktop
DOCX
MS SSAS 2008 & MDX Reports
DOCX
DBA Oracle,SQL Server, MYSQL,DB2 Express Postgres & Sybase
DOCX
Database Migration
DOCX
Cognos Express
DOCX
BI Apps ETL 4- Informatica PowerCenter Express
DOCX
Oracle ODI
DOCX
BI Apps Reports 4 Cognos BI and Crystal Reports
DOCX
Tableau Reports and Oracle OBIEE
DOCX
MS SSAS 2012 & MDX
DOCX
Advanced ETL2 Pentaho
DOCX
BI Apps Reports2- Oracle OBIEE & SAP Business Objects
DOCX
MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012
DOCX
BI Apps OLAP & Reports- SSAS 2012 Tabular & Multidimensional
DOCX
Advanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,Forms
DOCX
Advanced ETL MS SSIS 2012 & Talend
DOCX
DB Develop 2 Oracle 12c, DB2, MYSQL, SQL Anywhere 16
DOCX
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DOCX
DB Devlop- PostgreSQL 9.2.4 IQ 15.4
SQL Server and SSAS
BI Apps Reports 5 QlikSense Desktop
MS SSAS 2008 & MDX Reports
DBA Oracle,SQL Server, MYSQL,DB2 Express Postgres & Sybase
Database Migration
Cognos Express
BI Apps ETL 4- Informatica PowerCenter Express
Oracle ODI
BI Apps Reports 4 Cognos BI and Crystal Reports
Tableau Reports and Oracle OBIEE
MS SSAS 2012 & MDX
Advanced ETL2 Pentaho
BI Apps Reports2- Oracle OBIEE & SAP Business Objects
MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012
BI Apps OLAP & Reports- SSAS 2012 Tabular & Multidimensional
Advanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,Forms
Advanced ETL MS SSIS 2012 & Talend
DB Develop 2 Oracle 12c, DB2, MYSQL, SQL Anywhere 16
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Devlop- PostgreSQL 9.2.4 IQ 15.4

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Cloud computing and distributed systems.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
cuic standard and advanced reporting.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
Teaching material agriculture food technology
PDF
Encapsulation theory and applications.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
sap open course for s4hana steps from ECC to s4
Cloud computing and distributed systems.
Chapter 3 Spatial Domain Image Processing.pdf
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
cuic standard and advanced reporting.pdf
Programs and apps: productivity, graphics, security and other tools
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Teaching material agriculture food technology
Encapsulation theory and applications.pdf
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Spectral efficient network and resource selection model in 5G networks
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
A comparative analysis of optical character recognition models for extracting...

Relational / XML DB -SQL Server & Oracle Database