lower-case 函數 (XQuery)

lower-case 函數會將 $arg 中的每個字元轉換成小寫對等項目。Microsoft Windows Unicode 字碼元素的二進位大小寫轉換會指定字元如何轉換成小寫。這項標準與 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>