sql中not like
时间: 2023-10-31 16:54:30 浏览: 70
在SQL中,NOT LIKE是LIKE操作符的否定用法。如果LIKE匹配结果为true,则NOT LIKE的匹配结果为false,反之亦然。当然,前提是要排除null值的情况,因为null的结果始终为null。比如:
- Hive中的示例:
- `select 'abcde' like 'abc';` 结果为 false
- `select not 'abcde' like 'abc';` 结果为 true
- `select 'abcde' not like 'abc';` 结果为 true
- `select null like '%';` 结果为 NULL
- `select not null like '%';` 结果为 NULL
- `select null not like '%';` 结果为 NULL
- 另一个示例:
- `select 1 from t_fin_demo where NOT 'football' like 'fff%';` 结果为 1
- `select 1 from t_fin_demo where 'football' not like 'fff%';` 结果为 1
- `select 1 from t_fin_demo where 'football' like 'fff%';` 结果为 0
需要注意的是,当字符串A或字符串B为NULL时,结果也会是NULL。除了IS NULL和IS NOT NULL以外,其他关系运算符在遇到NULL值时,结果都是返回NULL,而不是TRUE或FALSE。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>