lower-case 函数 (XQuery)

lower-case 函数将 $arg 中的每个字符转换为其等效的小写字符。Unicode 码位的 Microsoft Windows 二进制大小写转换指定如何将字符转换为小写。这一标准与 Unicode 码位标准的映射不相同。

语法

fn:lower-case($arg as xs:string?) as xs:string

参数

术语

定义

$arg

要转换为小写的字符串值。

注释

如果 $arg 的值为空,则返回长度为零的字符串。

示例

A. 将字符串更改为小写

下面的示例将输入字符串“abcDEF!@4”更改为小写。

DECLARE @x xml = N'abcDEF!@4';
SELECT @x.value('fn:lower-case(/text()[1])', 'nvarchar(10)');

下面是结果集。

abcdef!@4

B. 搜索特定字符串

本示例演示如何使用 lower-case 函数来执行不区分大小写的搜索。

USE AdventureWorks
GO
--WITH XMLNAMESPACES clause specifies the namespace prefix
--to use. 
WITH XMLNAMESPACES ('https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription' AS pd)
--The XQuery contains() function is used to determine whether
--any of the text nodes below the <Summary> element contain
--the word 'frame'. The lower-case() function makes the 
--case insensitive.

SELECT ProductModelID, CatalogDescription.query('
      <Prod>
         { /pd:ProductDescription/@ProductModelID }
         { /pd:ProductDescription/pd:Summary }
      </Prod>
 ') as Result
FROM Production.ProductModel
where CatalogDescription.exist('
/pd:ProductDescription/pd:Summary//text()[
          contains(lower-case(.), "FRAME")]')  = 1

下面是结果集。

ProductModelID Result

-------------- ---------

19 <Prod ProductModelID="19">

<pd:Summary xmlns:pd="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription">

<p1:p xmlns:p1="http://www.w3.org/1999/xhtml">Our top-of-the-line competition mountain bike.

Performance-enhancing options include the innovative HL Frame,

super-smooth front suspension, and traction for all terrain.

</p1:p>

</pd:Summary>

</Prod>

25 <Prod ProductModelID="25">

<pd:Summary xmlns:pd="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription">

<p1:p xmlns:p1="http://www.w3.org/1999/xhtml">This bike is ridden by race winners.Developed with the

Adventure Works Cycles professional race team, it has a extremely light

heat-treated aluminum frame, and steering that allows precision control.

</p1:p>

</pd:Summary>

</Prod>