2013-03-04 3 views
0

나는이 지느러미 일 두 날짜를 비교하려는하지만 오라클 함수 안에 넣고 매개 변수로 날짜를 통과 할 때이 오류 얻을 오라클 쿼리가 있습니다오라클 비교 두 날짜

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; 

답변

2

plan_date 변수를 둘러싼 to_date 기능을 제거합니다.

plan_date은 이미 DATE 변수로 전달됩니다. to_date 함수를 사용하여 날짜로 변환 할 필요가 없습니다.

to_date 함수에 대해 말하면, 원하는 형식에 따라 문자열 (varchar2 유형)을 date 유형으로 변환하는 데 사용됩니다. 오라클 사이트 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;