问题
I have the following query:
$registros = Oportunidade::whereRaw("descricao REGEXP '[[:<:]]". $search ."[[:>:]]'")->get();
SQLSTATE[HY000]: General error: 1 no such function: REGEXP (SQL: select * from "oportunidades" where descricao REGEXP '[[:<:]]java[[:>:]]')
Also tried:
$registros = Oportunidade::where("descricao", "REGEXP", "'[[:<:]]'" .$search . "'[[:>:]]'")->get();
But for some reason I'm receiving this:
SQLSTATE[HY000]: General error: 1 no such function: REGEXP (SQL: select * from "oportunidades" where "descricao" REGEXP '[[:<:]]'java'[[:>:]]')
SQLSTATE[HY000]: General error: 1 no such function: REGEXP
Why am I getting this error and how could I fix it ? The query works perfect without laravel.
Why Doing this ?
I was using like %value%
:
SELECT * FROM mytable where description like %STRING%
The problem is: When I search for JAVA
it returns me even the records with JAVAscript
.
But, JAVA != JavaScript, right ? How can I work around it using Laravel
?
The only way I found using pure Mysql was with REGEXP
来源:https://stackoverflow.com/questions/47320448/using-regexp-with-laravel-query-builder