我想使用谓词notLike(表达式x,字符串模式)来替换以下查询:
select * from mytable
where mytable.myParameter not in ('ABC%','XYZ');但是当我使用以下谓词执行查询时:
Predicate notLike = builder.notLike(fromMyTable.get(MyTable_.myParameter), "ABC%|BCD");不起作用。
但是如果我为这两个字符串创建两个谓词:"ABC%“和"XYZ”是有效的。
是我的模式写错了,还是问题出在哪里?我尝试了很多方法来改变模式,但仍然不起作用。
谢谢!
发布于 2018-09-16 20:30:31
In SQL A not in (X,Y,Z) predicate是以下条件的快捷方式:
A <> X AND A <> Y AND A <> Z此条件使用“不等于”运算符,该运算符比较精确不相等的操作数。
不能使用IN或NOT IN运算符进行模式匹配。
您必须使用支持模式匹配的LIKE运算符重写查询:
select * from mytable
where mytable.myParameter not in ('XYZ')
and mytable.myParameter not LIKE 'ABC%';或
select * from mytable
where mytable.myParameter <> 'XYZ'
and mytable.myParameter not LIKE 'ABC%';https://stackoverflow.com/questions/52353992
复制相似问题