Xquery中[1]的意义是什么 [英] What is the significance of [1] in Xquery

查看:27
本文介绍了Xquery中[1]的意义是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 SQL Server 中 xquery 的新手.

I am new to xquery in SQL Server.

我经常遇到使用 [1] 和属性的 xquery 表达式.

I have often come across xquery expressions using [1] with attributes.

谁能解释一下这是什么意思?

Can somebody please explain what does it mean?

这是一个例子

declare @aa xml
set @aa='<data>
  <row>
    <Value>1</Value>
    <Text>Masters</Text>
  </row>
  <row>
    <Value>2</Value>
    <Text>Transactions</Text>
  </row>
  <row>
    <Value>3</Value>
    <Text>Misch. Reports</Text>
  </row>
</data>'


select a.f.value('Value[1]','varchar(50)'),   --  why [1] here ?
   a.f.value('Text[1]','varchar(50)')         --  and here too..
 from @aa.nodes('/data/row') as a(f)

谢谢n问候

推荐答案

在这种情况下,您是说您想要当前 /data/rowValue 元素> 和第一个 Text 元素相同.如果你把一个 [2] 放在那里,它意味着第二个.即使在您知道只有一行的地方放置 [1],您也可以确保只有一个元素会进入 value 函数.

In this case you're saying you want the first Value element for the current /data/row and the first Text element for the same. If you put a [2] there it will mean the second one. By putting a [1] even where you know there will be only one row, you make it feel safe that only one element will enter the value function.

这篇关于Xquery中[1]的意义是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆