gpt4 book ai didi

sql - 尝试从日期中提取月份时出错

转载 作者:行者123 更新时间:2023-12-04 05:21:05 26 4
gpt4 key购买 nike

我想从输入日期中提取月份。我正在尝试这个

select
case
when extract(month from :myDate) <= 6 then '1st'
when extract(month from :myDate) >= 7 then '2nd'
end as half_of_the_year
from dual

如果我输入 2-12-12然后我得到错误
ORA-30076: invalid extract field for extract source
30076. 00000 - "invalid extract field for extract source"
*Cause: The extract source does not contain the specified extract field.
*Action:

为什么我收到此错误?

谢谢

最佳答案

尝试使用 to_date 将绑定(bind)变量显式转换为日期数据类型功能:

select
case
when extract(month from to_date(:mydate, 'dd-mm-rr')) <= 6 then '1st'
when extract(month from to_date(:mydate, 'dd-mm-rr')) >= 7 then '2nd'
end as half_of_the_year
from dual

关于sql - 尝试从日期中提取月份时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13682947/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com