In mysql, like and regexp are implemented for Fuzzy queries. ------------------------ Many people know the usage of like. The most common case is select * fromawherenamelike % a %. % indicates any character, and its effect is like * in a regular expression *, it has several usage methods: a %, % a %, %,
In mysql, like and regexp are implemented for Fuzzy queries. ------------------------ Many people know the usage of like. The most common case is that select * from a where name like '% a %'. '%' indicates any character, it works like '*' in a regular expression. It has several usage methods: 'A % ',' % a % ',' % ',
In mysql, like and regexp are implemented for Fuzzy queries.
------------------------
Many people know the usage of like. The most common case is select * from a where name like '% a % ';
'%' Indicates any character, which is like '*' in a regular expression. It has several usage methods: 'A % ',' % a % ', '% A', which respectively indicates the start, existence, and end of the start.
You can also use the '_' character, which represents any character. The effect is similar to '.' in a regular expression '.'.
Like is a comparison of all strings in this field, and the efficiency is not high.
------------------------
Regexp is the regular expression matching operator of mysql.
The regexp usage is as follows: select * from a where name regexp 'A'. You can refer to the regular expression for its syntax. like '*', '[a-z]', 'a | B ', 'CC $', '^ B {2} $ '.
------------------------
Regexp is not directly used in hibernate, but it can be implemented by adding a custom function.
public class MySQL5DialectRegexp extends org.hibernate.dialect.MySQLInnoDBDialect{ public MySQL5DialectRegexp() { super(); registerFunction( "regexp", new SQLFunctionTemplate(Hibernate.BOOLEAN, "?1 REGEXP ?2") ); }}
Here, org. hibernate. dialect. MySQLInnoDBDialect is the value of hibernate. dialect in hibernate configuration information. You can use the path of MySQL5DialectRegexp instead.
HQL statements can be written:
From A where regexp (a, 'a | B | C') = 1;