【问题标题】:find upper case strings in SQL record or in Python在 SQL 记录或 Python 中查找大写字符串
【发布时间】:2016-05-01 13:25:23
【问题描述】:

如果存在的话,我需要在 SQL 或 Python 中查找字符串中以大写字母写成的单词。

例如,对于字符串:'My name is NOA',它将返回 NOA。

我想到的很长的路是使用 ascii 值: 如果 64

【问题讨论】:

  • 您使用的是什么数据库?请适当标记。

标签: python sql uppercase


【解决方案1】:

你可以使用string_split

假设你有这张桌子:

create table phrases (
    phrase varchar(200)
);

insert into phrases values ('My name is NOA');

然后你可以写:

select      phrase, value as uppercase_word
from        phrases
cross apply string_split(phrase, ' ')
where       upper(value) = value

使用给定的样本数据,它将返回:

phrase         | uppercase_word
---------------+---------------
My name is NOA | NOA

请务必记下文档中的这些信息:

STRING_SPLIT函数仅在兼容级别130下可用。如果您的数据库兼容级别低于130,SQL Server将无法找到并执行STRING_SPLIT函数。您可以使用以下命令更改数据库的兼容级别:ALTER DATABASE DatabaseName SET COMPATIBILITY_LEVEL = 130

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多