【问题标题】:PostgreSQL 9.3: STUFF and CHARINDEX functionPostgreSQL 9.3:STUFF 和 CHARINDEX 函数
【发布时间】:2015-03-10 06:35:42
【问题描述】:

我想检索给定字符串的一部分。

以下是字符串的示例:

示例:在 SQL Server 中

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

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

在提到这个之后:'stuff' and 'for xml path('')' from SQL Server in Postgresql

String_agg 在这种情况下无法帮助我。

【问题讨论】:

  • 那么stuff() 是做什么的?
  • @a_horse_with_no_name,它在开始位置删除第一个字符串中指定长度的字符,然后将第二个字符串插入到开始位置的第一个字符串中。语法:STUFF ( character_expression , start , length , replaceWith_expression ).
  • 你能展示一个输出的例子吗?或者描述你想要达到的目标。我的猜测 - regexp_replace() 可以解决问题,但我不明白你想做什么。

标签: postgresql postgresql-9.3


【解决方案1】:

您正在 PostgrSQL 中寻找与 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.

【讨论】:

    猜你喜欢
    • 2018-12-28
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    • 2015-03-25
    • 1970-01-01
    • 2023-03-06
    • 2014-06-08
    • 1970-01-01
    相关资源
    最近更新 更多