如何替换 Teradata select 语句中的多个字符串
How to replace multiple strings in a Teradata select statement
我需要从 table 中 select,但要删除各种字符串。
假设我的 table 中的条目是:
DataMart1:Here is some data and other valuable data
HouseWareMart Other data possibly junk data
DataLake3 there is nothing here
我想删除各种字符串:
"Valuable data"
"Other data "
"there is nothing "
所以我会得到:
DataMart1:Here is some data and other
HouseWareMart possibly junk data
DataLake3 here
我考虑过嵌套 OREPLACE,但语法不正确,搜索 'Nested OREPLACE' 没有任何帮助。
有什么建议吗?
嵌套替换的语法:
select oreplace(oreplace(oreplace(col, 'Valuable data', ''), 'Other data ', ''), 'there is nothing ', '')
注意:oReplace
区分大小写('Valuable data'
将不匹配 'valuable data'
)并且可能会在删除第一个匹配项后找到第二个匹配项,例如'DataLake3 there is valuable data nothing date'
首先删除 valuable data
,然后从剩余的字符串中删除 there is nothing
。
删除多个字符串的更简单方法是使用 regexp_replace
,区分大小写
RegExp_Replace(col, 'valuable data|other data|there is nothing')
或不区分大小写
RegExp_Replace(col, 'valuable data|other data|there is nothing', '', 1, 0, 'i')
我需要从 table 中 select,但要删除各种字符串。 假设我的 table 中的条目是:
DataMart1:Here is some data and other valuable data
HouseWareMart Other data possibly junk data
DataLake3 there is nothing here
我想删除各种字符串: "Valuable data" "Other data " "there is nothing "
所以我会得到:
DataMart1:Here is some data and other
HouseWareMart possibly junk data
DataLake3 here
我考虑过嵌套 OREPLACE,但语法不正确,搜索 'Nested OREPLACE' 没有任何帮助。
有什么建议吗?
嵌套替换的语法:
select oreplace(oreplace(oreplace(col, 'Valuable data', ''), 'Other data ', ''), 'there is nothing ', '')
注意:oReplace
区分大小写('Valuable data'
将不匹配 'valuable data'
)并且可能会在删除第一个匹配项后找到第二个匹配项,例如'DataLake3 there is valuable data nothing date'
首先删除 valuable data
,然后从剩余的字符串中删除 there is nothing
。
删除多个字符串的更简单方法是使用 regexp_replace
,区分大小写
RegExp_Replace(col, 'valuable data|other data|there is nothing')
或不区分大小写
RegExp_Replace(col, 'valuable data|other data|there is nothing', '', 1, 0, 'i')