本文介紹了用sql中的單個實例替換字符的多個實例的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
可能是重復的,但我找不到解決方案.
Probably it's a duplicate, but I couldn't find a solution.
要求:
我有以下字符串:
Heelloo
Heeelloo
Heeeelloo
Heeeeeelloo
Heeeeeeeelloo
.
.
.
Heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeelloo
預期輸出: Hello
在 SQL 中實現這一目標的最佳方法是什么?
What is the best way to achieve this in SQL?
我使用的版本:
Microsoft SQL Server 2012 - 10.0.7365.0 (X64) Jul 28 2015 00:39:54 Copyright (c)
Microsoft Corporation Parallel Data Warehouse (64-bit) on Windows NT 6.2 <X64>
(Build 9200: )
推薦答案
有一個很好的技巧可以刪除單個字母的重復項:
There is a nice trick for removing such duplicates for a single letter:
select replace(replace(replace(col, 'e', '<>'
), '><', ''
), '<>', 'e'
)
這確實需要兩個不在字符串中(或更具體地說,不在彼此相鄰的字符串中)的字符(<"和>").特定的字符并不重要.
This does require two characters ("<" and ">") that are not in the string (or more specifically, not in the string next to each other). The particular characters are not important.
這是如何工作的?
Heeello
H<><><>llo
H<>llo
Hello
這篇關于用sql中的單個實例替換字符的多個實例的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!