用 split_part 函数替换字符串
我想用“0,第一个单词”替换分隔符“,”之前的第一个单词)
select replace('tab,graph,map', split_part('tab,graph', ',', 1) like 'tab','0, tab')
错误:函数替换(未知,布尔值,未知)不存在 第 1 行:选择 Replace('tab,graph,map', split_part('tab,graph', ',',... ^ 提示:没有函数与给定的名称和参数类型匹配。您可能需要添加显式类型转换。
I want to replace the first word before delimeter ' ,' with ' 0, the first word ')
select replace('tab,graph,map', split_part('tab,graph', ',', 1) like 'tab','0, tab')
ERROR: function replace(unknown, boolean, unknown) does not exist
LINE 1: select replace('tab,graph,map', split_part('tab,graph', ',',...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
replace
函数会替换所有出现的字符串,因此您必须确保要替换的字符串是唯一的或使用其他字符串。但是,regexp_replace
< /a> 默认情况下仅替换第一个出现的位置,因此您可以使用它;你的问题有点不清楚预期的输出是什么,但也许这就是你正在寻找的:或者这个:
或者甚至可能是这个:
The
replace
function replaces all occurrences of the string so you have to make sure the string to replace is unique or use something else. However,regexp_replace
only replaces the first occurrence by default so you can use that; your question is a little unclear about what the expected output is but maybe this is is what you're looking for:Or this one:
Or maybe even this:
您需要进行强制转换,因为该函数需要替换(文本,文本,文本)并且不知道如何处理您的文字字符串,称它们为未知...
第二个参数也是 LIKE 比较吗?它返回布尔值,但函数替换期望它作为分隔符。
最后是最后一个参数(与第一个参数相同的问题)
当然,如果你真的只想在字符串“tab,graph,map”前面添加“0,”,你可以这样做......
you need to cast, since the function expects replace(text, text, text) and does not know how to handle your literal strings calling them unknown...
also the 2nd param is a LIKE comparison ? which returns boolean, but the function replace expects it to be the delimiter.
finally the last param (same problem as the first)
of course if you really just want to prepend '0, ' to your string, 'tab,graph,map' you could just do that...