我正在尝试在oracle中编写UDF,根据提供的日期和今天之间的差异返回一些。下面是我的代码和错误
Error(5,5): PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function pragma procedure subtype type <an identifier> <a double-quoted delimited-identifier> current cursor delete exists prior The symbol "begin" was substituted for "DECLARE" to continue.
CREATE OR REPLACE FUNCTION FN_AGE_RANGE(
SAP_DATE IN VARCHAR2 )
RETURN VARCHAR2
IS
ResultVar VARCHAR2;
-- Declare additional variables here
DECLARE
TheDate DATE;
TheDiff NUMBER;
BEGIN
--convert to date
SELECT
CASE
WHEN SAPDate = '00.00.0000'
THEN NULL
ELSE to_date(SAP_DATE,'dd.mm.yyyy')
END
INTO TheDate
FROM DUAL;
--workout date difference
SELECT DATEDIFF(d,GETDATE() , TheDate)
INTO TheDiff
FROM DUAL;
--set the frequency
SELECT
CASE
WHEN TheDiff < -180
THEN '>6 Months'
WHEN TheDiff < -90
THEN '3-6 Months'
WHEN TheDiff < 0
THEN '<3 Months'
END
INTO ResultVar
FROM DUAL;
RETURN(ResultVar);
END;
答案 0 :(得分:1)
https://docs.oracle.com/database/122/LNPLS/CREATE-PROCEDURE-statement.htm#LNPLS01373
decare部分不以关键字DECLARE
开头。删除它!