如何使用SQL切换字符串中每个字母的大小写? [英] How can I switch case for each letter in a string with SQL?
本文介绍了如何使用SQL切换字符串中每个字母的大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用PostgreSQL将其转换为此
I need to convert this into this using PostgreSQL
dxItw9a4 --> DXiTW9A4
是否已设置任何功能或方式?
Is there any function or way that is already set?
推荐答案
如果仅处理字符AZ,则可以使用 translate 函数可转换大小写。
If you're only dealing with the characters A-Z, you can use the translate function in postgres to convert cases.
select TRANSLATE(
'dxItw9a4', -- original text
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', -characters to change
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' -- replacement characters.
)
您可以简化
select TRANSLATE(
'dxItw9a4', -- original text
upper('dxItw9a4')||lower('dxItw9a4'), --characters to search for
lower('dxItw9a4')||upper('dxItw9a4') -- replacement characters
);
这篇关于如何使用SQL切换字符串中每个字母的大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文