Teradata的SQL:查询一栏为具有空间格局(又名where子句来搜索具有空间,在一个字符串的模式)
问题描述:
我能做到这一点Teradata的SQL:查询一栏为具有空间格局(又名where子句来搜索具有空间,在一个字符串的模式)
where Col like '%Mystring%String2%'
在Teradata的SQL或我可以使用单个字符匹配的?
。如何搜索 这样的内容模式,使用Terdata SQL正则表达式 String<one of more instance of spaces or non alpha chars>string2
IS NOT NULL
或IS NOT NULL
在两个或多个字符串之间有一个或多个空格或其他非字母字符的实例 E.g.考虑这个字符串,它是在PDCR
数据库sqltext
的一部分
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%','%||||%')
注意NOT
和NULL
和IS
和NULL
间空隙的变化AMT所以我想成立一个where
条款,倒是检查各种非alpha的条件,如(这是更多的伪代码like。sorry abt that)
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
条款
答
使用正则表达式\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,这是因为你不有点短在开始和结束时不需要“任何字符”:
WHERE REGEXP_INSTR(x,'IS[\s|\|]+NOT',1,1,0,'i') > 0
+0
神话般的节食者! – user1874594
数据和期望结果的一些示例将有助于理解您的问题。 \t请阅读[**如何提问**](http://stackoverflow.com/help/how-to-ask) \t \t这里是[** START **]( http://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/)了解如何提高您的问题质量并获得更好的答案。 –
定义*非alpha字符*,可能类似于'REGEXP_SIMILAR(col,'。*?string [^ a-z] + string2。*?','i')' – dnoeth
谢谢。我已经给出了例子。我不是在寻找这里的输入,我想要这种输出类型的答案。 – user1874594