SQL XML process
15815 단어 process
declare @data xml
set @data='
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="jp">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="cn">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
'
--1、
select @data
--2、 price
select @data.exist('//price')
--3、 book
select @data.query('//book')
--4、 lang
select @data.query('//*[@lang]')
--5、 book
select @data.query('//book[1]')
--6、 book
select @data.query('//book[position()<=2]')
--7、 book
select @data.query('//book[last()]')
--8、 price>35 book
select @data.query('//book[price>35]')
--9、 category="WEB" book
select @data.query('//book[@category="WEB"]')
--10、 title lang="en" book
select @data.query('//book/title[@lang="en"]')
--11、 title lang="en" price>35 book
select @data.query('//book[./title[@lang="en"] or price>35 ]')
--12、 title lang="en" price>35 book ( )title
select @data.query('//book[./title[@lang="en"] and price>35 ]').value('(book/title)[1]','varchar(max)')
--13、 12
select @data.value('(//book[./title[@lang="en"] and price>35 ]/title)[1]','varchar(max)')
--14、 title lang="en" price>35 book ( )title lang
select @data.value('((//book[@category="WEB" and price>35 ]/title)[1]/@lang)[1]','varchar(max)')
--15、 title
select Tab.Col.value('(book/title)[1]','varchar(max)') as title
from @data.nodes('bookstore')as Tab(Col)
--16、 author
select Tab.Col.value('author[1]','varchar(max)') as title
from @data.nodes('//book')as Tab(Col)
--17、 book
select
T.C.value('title[1]','varchar(max)') as title,
T.C.value('year[1]','int') as year,
T.C.value('title[1]','varchar(max)')as title,
T.C.value('price[1]','float') as price,
T.C.value('author[1]','varchar(max)') as author1,
T.C.value('author[2]','varchar(max)') as author2,
T.C.value('author[3]','varchar(max)') as author3,
T.C.value('author[4]','varchar(max)') as author4
from @data.nodes('//book') as T(C)
--18、 (lang!="jp") 35
select
T.C.value('title[1]','varchar(max)') as title,
T.C.value('year[1]','int') as year,
T.C.value('title[1]','varchar(max)')as title,
T.C.value('price[1]','float') as price,
T.C.value('author[1]','varchar(max)') as author1,
T.C.value('author[2]','varchar(max)') as author2,
T.C.value('author[3]','varchar(max)') as author3,
T.C.value('author[4]','varchar(max)') as author4
from @data.nodes('//book[./title[@lang!="jp"] and price>35 ]') as T(C)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
메모리 프로세스 보기 Powershell백분율로 메모리 사용량 얻기 상위 5개 프로세스 메모리 사용량(MB)...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.