甲骨文比较两个日期
问题描述:
我有Oracle查询我要比较两个日期它的工作片,但是当我把它放在Oracle函数里面并传递一个日期作为参数,我得到这个错误:甲骨文比较两个日期
ORA-01843: not a valid month
ORA-06512: at line 8
Process exited.
,这我的功能:
Create or Replace
FUNCTION GET_MAX_VALUE
(
PLAN_DATE IN DATE
, LOC IN NUMBER
, RES IN NUMBER
, TIS IN NUMBER
) RETURN NUMBER AS
units number;
return_val number;
BEGIN
select ts.booked_units into units from tsm_transaction_tbl ts
where ts.location_id=loc and ts.resource_id=res and ts.ts_id=tis and ts.trans_date=to_date(plan_date,'mm/dd/yyyy');
RETURN units;
END GET_MAX_VALUE;
答
删除包围你的plan_date
变量to_date
功能。
您已经通过plan_date
作为DATE
类型变量。无需使用to_date
函数将其转换为日期。
说到to_date
函数,它用于根据我们想要的格式将字符串(varchar2类型)转换为date
类型。您可以在Oracle的网站here上阅读有关to_date
函数的更多信息。
您的代码可以如下:
Create or Replace
FUNCTION GET_MAX_VALUE
(
PLAN_DATE IN DATE
, LOC IN NUMBER
, RES IN NUMBER
, TIS IN NUMBER
) RETURN NUMBER AS
units number;
return_val number;
BEGIN
select ts.booked_units into units from tsm_transaction_tbl ts
where ts.location_id=loc
and ts.resource_id=res
and ts.ts_id=tis
and ts.trans_date = plan_date;
RETURN units;
END GET_MAX_VALUE;