大家好,我需要提取"."之前的第一个字符,然后提取其余字符



这是一个SQL实例,示例如下:

要转换的表值:

字符串为Donald.Duck,所需结果为DDuck字符串是Mickey。Mouse,所需结果是MMouse

您可以在sql中使用正则表达式。它运行速度较慢,但将使用dot.net框架

正则表达式很简单。向前看并找到一个句点,然后捕获该句点中的所有非空格字符。

如何在tsql中调用正则表达式

https://www.sqlshack.com/t-sql-regex-commands-in-sql-server/

#extract the data to a csv then process it and update back into the database
txt="Donald.Duck and the desired result is DDuck String other strings are Mickey.Mouse and Daffy.Duck"
pattern = re.compile(r'([a-zA-Z]+.[a-zA-Z]+)')
result=re.findall(pattern,txt)
for item in result:
front,back=item.split('.')
txt=re.sub(item, front[0]+'.'+back,txt)
print(txt)

输出

Donald.Duck and the desired result is DDuck String other strings are Mickey.Mouse and Daffy.Duck

Sql步骤:

  1. 按空格将单词拆分成单词表
  2. 提取每个单词并执行instr以检查句点
  3. 按句点拆分前后单词
  4. 保留前面单词的第一个字符,重新组合并替换短语
  5. 将单词组合成一个句子,并用新句子更新数据库

最新更新