【问题标题】:How to filter data from a stored procedure using when clause or where clause?如何使用 when 子句或 where 子句从存储过程中过滤数据?
【发布时间】:2021-01-22 04:55:20
【问题描述】:

以下是我的代码,我想从存储过程中获取数据并使用 where 子句过滤数据,但 where 或 when 不适用于 select 子句;

DB::select('exec my_stored_procedure(?,?)', [$a, $b])
-> where(// condition);   //this is not working

【问题讨论】:

  • DB::select('exec my_stored_procedure(?,?)', [$a, $b]) 的结果是否返回查询构建器实例?因为您只能在查询生成器上使用 where
  • 我建议您将 where 条件构建到存储过程中:)
  • 我通过执行存储过程得到了数组的结果,但我想在其中添加条件。有什么方法可以在 laravel 中实现这一点? @派对环

标签: php laravel laravel-5 laravel-query-builder


【解决方案1】:

对于 laravel 存储过程中的 Where 条件,首先您必须在过程中定义结果集,并且对于您在过程结果中定义的那些变量或列名用于结果集中的 where 条件。

程序使用:Result(Column_name)

对于 Laravel 使用:DB::select('exec my_stored_procedure(?,?) where Column_name = ?', [$a, $b,$c])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-05-05
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    相关资源
    最近更新 更多