0

我有 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;
4

1 回答 1

2

删除围绕变量的to_date函数。plan_date

您已经plan_date作为DATE类型变量传递。无需使用to_date函数将其转换为日期。

说到to_date函数,它用于将字符串(varchar2 类型)转换为date我们想要的格式的类型。您可以在此处to_date阅读有关Oracle 网站上的功能的更多信息。

您的代码可以如下所示:

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;
于 2013-03-04T15:50:13.253 回答