古詩詞大全網 - 成語查詢 - sql中怎麽提取大寫字母,例如給了壹個人的英文姓名,然後用它們的首字母做縮寫,Lily James LJ

sql中怎麽提取大寫字母,例如給了壹個人的英文姓名,然後用它們的首字母做縮寫,Lily James LJ

-----In Oracle

select

replace(

replace(

translate(

'Lily James',

'abcdefghijklmnopqrstuvwxyz',

rapd('#',26,'#')

),

'#',

''),

' ',

'')

from t1

--In MSSQL

create function udf_GetFirst

(

@string varchar(max)

)

return varchar(max)

begin

declare @length int,@increment int,@newString varchar(max)

declare @curChar char(1),@preChar char(1)

set @length=len(@string)

set @increment=1

set @newString=''

set @preChar=' '

set @string=lower(@string)

while @increment<=@length

begin

set @curChar=substring(@string,@increment,1)

set @newString=@newString+

case when @preChar=' '

then upper(@curChar) else @curChar end

set @preChar=@curChar

end

return(@newString)

end