错误消息:ORA-01841尝试按日期过滤记录

发布于 2025-02-11 09:56:35 字数 785 浏览 1 评论 0原文

我正在使用Laravel应用程序使用Oracle数据库 我有记录模型及其数据库表是items_view它是一个数据库视图,现在我想用'Invh_dt' column(这是日期类型)等于特定日期,所以我正在使用此错误:

$records = Record::where('INVH_DT', 'to_date(\'22/06/2022\' , \'DD/MM/YYYY\')' )->get();

但是我有一个错误:

错误代码:1841错误消息:ORA -01841 :(完整)年度必须在-4713和+9999之间,并且不是0位置:46语句:从“ tooks_view”中select * select * where“ inveh_dt” where'invh_dt“ where” =: p0> bindings:[to_date('22/06/2022','dd/mm/yyyy']]] 选择 * 从 “ ittem_view” 在哪里 “ Invh_dt” = to_date('22/06/2022','dd/mm/yyyy')

我尝试了此语句elect * epleion * elect * eflect * every_view“ where” wend Oracle SQL开发人员上的'dd/mm/yyyy')它可以正常运行。 我尝试了其他日期格式,例如'yyyymmdd',并且在SQL开发人员中效果很好,同时给出了Laravel相同的错误。

I am using Oracle Database with Laravel application
I have Record model and its database table is items_view which is a Database View, now I want to get all records with 'INVH_DT' column (which is of date type) equals to a specific date so I am using this:

$records = Record::where('INVH_DT', 'to_date(\'22/06/2022\' , \'DD/MM/YYYY\')' )->get();

but I have this error:

Error Code : 1841 Error Message : ORA-01841: (full) year must be between -4713 and +9999, >and not be 0 Position : 46 Statement : select * from "ITEMS_VIEW" where "INVH_DT" = :p0 >Bindings : [to_date('22/06/2022' , 'DD/MM/YYYY')]
select
*
from
"ITEMS_VIEW"
where
"INVH_DT" = to_date('22/06/2022', 'DD/MM/YYYY')

I tried this statement elect * from "ITEMS_VIEW" where "INVH_DT" = to_date('22/06/2022' , 'DD/MM/YYYY') on Oracle SQL Developer and it works fine.
I tried other date formats like 'YYYYMMDD' and it works fine on SQL Developer while giving the same error of Laravel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味拾荒者 2025-02-18 09:56:35

我不知道Laravel,但是由此产生的SQL命令看起来像这样:

select * from "ITEMS_VIEW" where "INVH_DT" = :p0

其中:P0参数被to_date替换('22/06/2022','dd/mm/yyyy ')。它不会那样工作。

也许尝试一下:

$records = Record::where("to_char(INVH_DT, 'DD/MM/YYYY')", '22/06/2022')->get();

I don't know Laravel, but the resulting SQL command looks like this:

select * from "ITEMS_VIEW" where "INVH_DT" = :p0

where the :p0 parameter is replaced with to_date('22/06/2022' , 'DD/MM/YYYY'). It will not work that way.

Maybe try this:

$records = Record::where("to_char(INVH_DT, 'DD/MM/YYYY')", '22/06/2022')->get();
懒的傷心 2025-02-18 09:56:35

我发现Laravel通过查询构建器的whereDate条款其他条款
这只是按预期工作:

$records = Record::whereDate('INVH_DT', '2022-06-22')->get();

I figured out that Laravel deals with this issue by Query builder's whereDate clause Additional Where Clauses
and this just worked as expected:

$records = Record::whereDate('INVH_DT', '2022-06-22')->get();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文