如何替换Netezza列中的转义字符 [英] How to replace escape character in Netezza column

查看:244
本文介绍了如何替换Netezza列中的转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试替换Netezza列中的转义字符,但不能正确替换. 请帮我解决这个问题.

I am trying to replace escape character in Netezza column, but it is not properly replacing. Please help me some one on this.

select replace('replaces\tring','\','\\\\');

我需要输出为replaces\\\\tring.以下是我收到的错误消息...

I need output as replaces\\\\tring. Below is the error message i am getting...

错误[42S02]错误:函数'REPLACE(UNKNOWN,UNKNOWN,UNKNOWN)' 不存在无法识别满足给定功能的功能 参数类型您可能需要添加显式的类型转换

ERROR [42S02] ERROR: Function 'REPLACE(UNKNOWN, UNKNOWN, UNKNOWN)' does not exist Unable to identify a function that satisfies the given argument types You may need to add explicit typecasts

谢谢.

推荐答案

这是因为需要安装REPLACE函数(默认情况下未安装).还有另一个称为TRANSLATE的函数,可以代替REPLACE有限地使用它,但不幸的是,它不适合您的情况.

This is because REPLACE function needs to be installed (which is not by default). There is another function which is called TRANSLATE which can be used in a limited way instead of REPLACE but unfortunately won't fit in your situation.

您可以改为使用以下查询:

You can use the below query instead:

SELECT SUBSTRING(x, 1, INSTR(x, '\') - 1) || '\\\\' || SUBSTRING(x, INSTR(x, '\') + LENGTH('\')) FROM 
(SELECT 'replaces\tring' AS x) t

    传递给INSTR
  • \LENGTH是要替换的字符串.请注意,它们出现在三个位置.
  • 中间的
  • \\\\是替换字符串.
  • replaces\tring是要搜索的字符串.
    • \ passed to INSTR and LENGTH is the string to be replaced. Note that they occur in three positions.
    • \\\\ in the middle is the replacement string.
    • replaces\tring is the string to search in.
    • 在下面的示例中,将我爱Netezza 中的喜欢替换为:

      Check the below example for replace love with like in I love Netezza:

      SELECT SUBSTRING(x, 1, INSTR(x, 'love') - 1) || 'like' || SUBSTRING(x, INSTR(x, 'love') + LENGTH('love')) FROM 
      (SELECT 'I love Netezza' AS x) t
      

      这篇关于如何替换Netezza列中的转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆