PostgreSQL 9.3:STUFF和CHARINDEX函数

7

我可以帮助您翻译,以下是关于it技术的内容:

我想要获取给定字符串的某些部分。

以下是字符串的示例:

示例: 在SQL Server中

Declare @Names varchar = 'H1,H2,H3,'

SELECT STUFF(@Names,1,CHARINDEX(',',@Names,0),'');

在参考了这篇文章之后:SQL Server中的'stuff'和'for xml path('')'在PostgreSQL中的应用String_agg对于我的情况无法帮助我。

那么 stuff() 函数是做什么的? - user330315
@a_horse_with_no_name,它会在第一个字符串的起始位置删除指定长度的字符,然后将第二个字符串插入到第一个字符串的起始位置。语法:STUFF(character_expression,start,length,replaceWith_expression) - MAK
2
你能展示一个输出的例子吗?或者描述一下你想要实现什么。我的猜测是使用 regexp_replace() 可以解决,但我不明白你想做什么。 - Ihor Romanchenko
1个回答

9
您正在寻找PostgreSQL中与STUFF等效的TSQL函数,我认为这个函数是:overlay
例如:
SELECT STUFF('abcdef', 2, 3, 'ijklmn');

select overlay('abcdef' placing 'ijklmn' from 2 for 3)

给出相同的结果,即;

'aijklmnef'

换句话说:

They inserts a string into another string. It deletes a specified length of characters in the 
first string at the start position and then inserts the second string into the first string at 
the start position.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接