【问题标题】:Oracle compare two dateOracle比较两个日期
【发布时间】:2013-03-04 15:48:10
【问题描述】:

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

【问题讨论】:

    标签: oracle function plsql


    【解决方案1】:

    删除围绕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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      • 2013-11-29
      • 1970-01-01
      相关资源
      最近更新 更多