根据字符串长度使用 like

Using like depending on string length

我必须过滤一个列,我从该列中获取的数据看起来不像 '66******1''66*******1'。那么如何使用不同字符串长度的 LIKE 呢?

你可能想要 regexp_like():

where not regexp_like(col, '^66[*]{6,7}1$')

如果*意指任何字符,则:

where not regexp_like(col, '^66.{6,7}1$')

您可以使用通配符测试两个字符数:

where (your_col not like '66______1' and your_col not like '66_______1')

如果您的意思是 66 和 1 之间的任意 个字符,那么您可以改用 % 通配符:

where your_col not like '66%1'

这将排除 661、66*1、66**1 等

或者,可能,普通 SUBSTR:

where substr(col, 1, 2) <> '66'
   or substr(col, -1)   <> '1'

我们为什么要把它复杂化

where  column not like '66_______1' or column not like  '66______1'

很简单

WHERE col NOT LIKE '66%1'