Bagikan melalui


Fungsi pada Nilai String - huruf kecil

Berlaku untuk:SQL Server

Fungsi huruf kecil mengonversi setiap karakter dalam $arg ke huruf kecil yang setara. Konversi kasus biner Microsoft Windows untuk titik kode Unicode menentukan bagaimana karakter dikonversi ke huruf kecil. Standar ini tidak identik dengan pemetaan untuk standar titik kode Unicode.

Sintaks

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

Argumen

Term Definisi
$arg Nilai string yang akan dikonversi ke huruf kecil.

Keterangan

Jika nilai $arg kosong, string panjang nol dikembalikan.

Contoh

J. Mengubah string menjadi huruf kecil

Contoh berikut mengubah string input 'abcDEF!@4' menjadi huruf kecil.

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

Berikut set hasilnya.

abcdef!@4

B. Mencari string karakter tertentu

Contoh ini menunjukkan kepada Anda cara menggunakan fungsi huruf kecil untuk melakukan pencarian tidak peka huruf besar/kecil.

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  

Berikut set hasilnya.

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>

Lihat Juga

Fungsi XQuery terhadap Tipe Data xml