字串值的相關函式 - lower-case
適用於:SQL Server
小寫函式會將$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. 搜尋特定字元字串
此範例示範如何使用小寫函式來執行不區分大小寫的搜尋。
USE AdventureWorks2022;
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>