Teradata SQL:查询具有空格的模式的列(a.k.a是一个where子句,用于搜索字符串中包含空格的模式)

时间:2016-03-08 20:29:41

标签: sql regex database teradata sqlperformance

我可以这样做

where Col  like '%Mystring%String2%' 

在Teradata SQL中,我可以使用?进行单个字符匹配。我该如何搜索 使用Terdata SQL Regex的内容模式是这样的   
String<one of more instance of spaces or non alpha chars>string2 例如 IS NOT NULL
IS NOT NULL 2个或更多字符串之间有1个或多个空格实例或其他非字母字符 例如。考虑这个字符串是sqltext数据库中PDCR的一部分

sel t1.c1, t2.c2, t3.c3 from 
t1 , t2 ,t3
where t2.Cx is NULL and t3.cy IS NOT NULL and 
t3.Ca is         NULL          AND 
t3.cb is NULL AND          t3.c7 is        NOT NULL 
and t3.c10 not like  any ('%searchstring%','%string%','%||||%')

请注意NOTNULL以及ISNULL

之间不同的空格

所以我想形成where条款,检查各种非alpha条件,例如(这是更多伪代码,例如。不好意思)

 where Sqltext like '%NOT<1 or more instances of Spaces only>NULL%' 
    or SQLtext like  '%,\%<one or more instances of | character%' escape '\'

这就是我要找的东西。 REGEXP_SIMILAR似乎很有希望。试着用where子句

来了解它是如何变长的

1 个答案:

答案 0 :(得分:2)

使用正则表达式\s查找空格(空格,制表符,CRLF):

WHERE REGEXP_SIMILAR(col,'.*?IS[\s|\|]+NOT.*?','i') = 1

.*?                    -- any characters
   IS                  -- 1st string
     [\s|\|]+          -- one or more whitespaces and/or | 
             NOT       -- 2nd string
                .*?'   -- any characters

或REGEXP_INSTR,因为你不需要&#34;任何字符&#34;在开始和结束时:

WHERE REGEXP_INSTR(x,'IS[\s|\|]+NOT',1,1,0,'i') > 0