本文介紹了將 PascalCase 字符串轉(zhuǎn)換為“友好名稱(chēng)"在 TSQL 中的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
我有一個(gè)表,其中一列的值來(lái)自枚舉.我需要?jiǎng)?chuàng)建一個(gè) TSQL 函數(shù),以便在檢索時(shí)將這些值轉(zhuǎn)換為友好名稱(chēng)".
I have a table with a column whose values come from an Enumeration. I need to create a TSQL function to convert these values to "Friendly Names" upon retrieval.
示例:
'DateOfBirth' --> 'Date Of Birth'
'PrincipalStreetAddress' --> 'Principal Street Address'
我需要一個(gè)直接的 TSQL UDF 解決方案.我沒(méi)有安裝擴(kuò)展存儲(chǔ)過(guò)程或 CLR 代碼的選項(xiàng).
I need a straight TSQL UDF solution. I don't have the option of installing Extended Store Procedures or CLR code.
推薦答案
/*
Try this. It's a first hack - still has problem of adding extra space
at start if first char is in upper case.
*/
create function udf_FriendlyName(@PascalName varchar(max))
returns varchar(max)
as
begin
declare @char char(1)
set @char = 'A'
-- Loop through the letters A - Z, replace them with a space and the letter
while ascii(@char) <= ascii('Z')
begin
set @PascalName = replace(@PascalName, @char collate Latin1_General_CS_AS, ' ' + @char)
set @char = char(ascii(@char) + 1)
end
return LTRIM(@PascalName) --remove extra space at the beginning
end
這篇關(guān)于將 PascalCase 字符串轉(zhuǎn)換為“友好名稱(chēng)"在 TSQL 中的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!