You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Lumen8中Eloquent Where查询返回错误结果及配置差异排查

Laravel/Lumen 8.3.4 查询Oracle数据库结果异常

环境与数据库数据

使用Laravel/Lumen 8.3.4版本,Oracle数据库中存在以下4条数据:

IDFOREIGN_IDNAME
1100Entry1
2100Entry2
3100Entry3
4200Entry4

模型代码

Entry模型代码如下:

class Entry extends Model
{
    protected $connection = 'MyConnection';
    protected $table = 'MY_TABLE';
    protected $fillable = ['foreign_id', 'name'];
    protected $hidden =  ['foreign_id'];
    protected $casts = [
        'foreign_id' => 'integer'
    ];
}

查询异常现象

执行以下查询时,预期返回空集合,但实际只返回ID为1的Entry1:

Entry::where([['id', '!=', 1], 'foreign_id' => 100, 'name' => 'Entry1'])->get();

分步添加Where条件测试:

  • 以下查询返回除Entry1外的所有数据,结果正确:
    Entry::where(['id', '!=', 1])->get();
    
  • 以下查询返回Entry2和Entry3,结果正确:
    Entry::where(['id', '!=', 1])->where(['foreign_id' => 100])->get(); 
    
  • 以下查询只返回Entry1,结果错误(预期为空集合):
    Entry::where(['id', '!=', 1])->where(['foreign_id' => 100])->where(['name' => 'Entry1'])->get(); 
    

生成的SQL语句

查询生成的SQL语句为:

"select * from "MY_TABLE" where ("ID" != ? and "FOREIGN_ID" = ? and "NAME" = ?)"

疑问

在另一台电脑上执行该查询返回空集合,将!=替换为not like后问题解决,请问是什么配置差异导致了这种情况?

内容的提问来源于stack exchange,提问作者Febertson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 11:56:35